Пример #1
0
  /**
   * Draw into this image the provided image at the given coordinates. Parts of the image outside
   * the bounds of this image will be ignored.
   *
   * @param image The image to draw.
   * @param x The x-coordinate of the top-left of the image
   * @param y The y-coordinate of the top-left of the image
   */
  public void drawImage(final I image, final int x, final int y) {
    final int stopx = Math.min(this.targetImage.getWidth(), x + image.getWidth());
    final int stopy = Math.min(this.targetImage.getHeight(), y + image.getHeight());
    final int startx = Math.max(0, x);
    final int starty = Math.max(0, y);

    for (int yy = starty; yy < stopy; yy++)
      for (int xx = startx; xx < stopx; xx++)
        this.targetImage.setPixel(xx, yy, image.getPixel(xx - x, yy - y));
  }
Пример #2
0
  /**
   * Draw into this image the provided image at the given coordinates ignoring certain pixels. Parts
   * of the image outside the bounds of this image will be ignored. Pixels in the ignore list will
   * be stripped from the image to draw.
   *
   * @param image The image to draw.
   * @param x The x-coordinate of the top-left of the image
   * @param y The y-coordinate of the top-left of the image
   * @param ignoreList The list of pixels to ignore when copying the image
   */
  public void drawImage(
      final I image,
      final int x,
      final int y,
      @SuppressWarnings("unchecked") final Q... ignoreList) {
    final int stopx = Math.min(this.targetImage.getWidth(), x + image.getWidth());
    final int stopy = Math.min(this.targetImage.getHeight(), y + image.getHeight());
    final int startx = Math.max(0, x);
    final int starty = Math.max(0, y);

    for (int yy = starty; yy < stopy; yy++)
      for (int xx = startx; xx < stopx; xx++) {
        final Q val = image.getPixel(xx - x, yy - y);
        if (Arrays.binarySearch(ignoreList, val, this.targetImage.getPixelComparator()) < 0)
          this.targetImage.setPixel(xx, yy, val);
      }
  }