Exemplo n.º 1
0
 /** @see Graphics2D#drawImage(BufferedImage, BufferedImageOp, int, int) */
 public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
   BufferedImage result = img;
   if (op != null) {
     result = op.createCompatibleDestImage(img, img.getColorModel());
     result = op.filter(img, result);
   }
   drawImage(result, x, y, null);
 }
Exemplo n.º 2
0
  /**
   * @see Graphics#drawImage(Image, int, int, int, int, int, int, int, int, Color, ImageObserver)
   */
  public boolean drawImage(
      Image img,
      int dx1,
      int dy1,
      int dx2,
      int dy2,
      int sx1,
      int sy1,
      int sx2,
      int sy2,
      Color bgcolor,
      ImageObserver observer) {
    waitForImage(img);
    double dwidth = (double) dx2 - dx1;
    double dheight = (double) dy2 - dy1;
    double swidth = (double) sx2 - sx1;
    double sheight = (double) sy2 - sy1;

    // if either width or height is 0, then there is nothing to draw
    if (dwidth == 0 || dheight == 0 || swidth == 0 || sheight == 0) return true;

    double scalex = dwidth / swidth;
    double scaley = dheight / sheight;

    double transx = sx1 * scalex;
    double transy = sy1 * scaley;
    AffineTransform tx = AffineTransform.getTranslateInstance(dx1 - transx, dy1 - transy);
    tx.scale(scalex, scaley);

    BufferedImage mask =
        new BufferedImage(
            img.getWidth(observer), img.getHeight(observer), BufferedImage.TYPE_BYTE_BINARY);
    Graphics g = mask.getGraphics();
    g.fillRect(sx1, sy1, (int) swidth, (int) sheight);
    drawImage(img, mask, tx, null, observer);
    g.dispose();
    return true;
  }
Exemplo n.º 3
0
 /** @see Graphics2D#drawRenderedImage(RenderedImage, AffineTransform) */
 public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
   BufferedImage image = null;
   if (img instanceof BufferedImage) {
     image = (BufferedImage) img;
   } else {
     ColorModel cm = img.getColorModel();
     int width = img.getWidth();
     int height = img.getHeight();
     WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
     boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
     Hashtable properties = new Hashtable();
     String[] keys = img.getPropertyNames();
     if (keys != null) {
       for (int i = 0; i < keys.length; i++) {
         properties.put(keys[i], img.getProperty(keys[i]));
       }
     }
     BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties);
     img.copyData(raster);
     image = result;
   }
   drawImage(image, xform, null);
 }