Java Draw Image drawImageInOval(Graphics2D gr, Image img, Rectangle r, boolean noShrink)

Here you can find the source of drawImageInOval(Graphics2D gr, Image img, Rectangle r, boolean noShrink)

Description

draw an image in a rectangle

License

Apache License

Parameter

Parameter Description
gr non-null graphic context
img non-null image
r non-null rectangle
obs non-null observer

Declaration

public static void drawImageInOval(Graphics2D gr, Image img, Rectangle r, boolean noShrink) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.*;

import java.awt.geom.Ellipse2D;

public class Main {
    /**/*from  w  w w.  ja  v  a 2  s .co  m*/
     * draw an image in a rectangle
     *
     * @param gr  non-null graphic context
     * @param img non-null image
     * @param r   non-null rectangle
     * @param obs non-null observer
     */
    public static void drawImageInOval(Graphics2D gr, Image img, Rectangle r, boolean noShrink) {
        Shape oldclip = gr.getClip();
        Ellipse2D clip = new Ellipse2D.Double(r.getX(), r.getY(), r.getWidth(), r.getHeight());
        gr.clip(clip);
        if (noShrink) {
            int imgwidth = img.getWidth(null);
            int imgheight = img.getHeight(null);
            if (imgwidth > r.width && imgheight > r.height)
                gr.drawImage(img, r.x, r.y, imgwidth, imgheight, null);
            else
                gr.drawImage(img, r.x, r.y, r.width, r.height, null);
        } else {
            gr.drawImage(img, r.x, r.y, r.width, r.height, null);
        }
        gr.clip(oldclip);
    }
}

Related

  1. drawImage(Graphics2D g2d, BufferedImage image, Rectangle dispArea)
  2. drawImage(Image image, Dimension windowSize, Graphics graphics)
  3. drawImage(Image image, Graphics g, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2)
  4. drawImage(Image img, double x, double y, Graphics2D graphics)
  5. drawImageClip(Graphics g, BufferedImage image, ImageObserver observer)
  6. drawImageInPolygon(Graphics g2d, BufferedImage img, Polygon poly, double xfactor, double yfactor)
  7. drawImageInRect(Graphics g2d, BufferedImage img, Rectangle rect, double xfactor, double yfactor)
  8. drawImageInRect(Graphics2D gr, Image img, Rectangle r, boolean noShrink)
  9. drawImageWithClipping(Graphics g, BufferedImage img)