Java Utililty Methods Draw Image

List of utility methods to do Draw Image

Description

The list of methods to do Draw Image are organized into topic(s).

Method

voiddrawImage(Graphics graphics, Component comp, Image image)
draw Image
Dimension d = comp.size();
graphics.setColor(comp.getBackground());
graphics.fillRect(0, 0, d.width, d.height);
graphics.drawImage(image, (d.width - image.getWidth(null)) / 2, (d.height - image.getHeight(null)) / 2,
        null);
voiddrawImage(Graphics2D g, BufferedImage image, int x, int y)
Malt ein BufferedImage auf ein Graphics2D-Objekt.
g.drawImage(image, x, y, null);
voiddrawImage(Graphics2D g2d, BufferedImage image, Rectangle dispArea)
draw Image
int wt = image.getWidth();
int ht = image.getHeight();
int x = dispArea.x + (int) ((dispArea.width - wt) / 2);
int y = dispArea.y + (int) ((dispArea.height - ht) / 2);
g2d.drawImage(image, x, y, wt, ht, null);
double[]drawImage(Image image, Dimension windowSize, Graphics graphics)
draw Image
double size[] = getResize(image, windowSize);
graphics.drawImage(image, 0, 0, (int) size[0], (int) size[1], null);
return size;
voiddrawImage(Image image, Graphics g, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2)
draw Image
if (dx2 - dx1 <= 0 || dy2 - dy1 <= 0 || sx2 - sx1 <= 0 || sy2 - sy1 <= 0) {
    return;
g.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
Graphics2DdrawImage(Image img, double x, double y, Graphics2D graphics)
Draws an entire image (full size) at the specified coordinates.
graphics.drawImage(img, round(x), round(y), null);
return graphics;
voiddrawImageClip(Graphics g, BufferedImage image, ImageObserver observer)
Draws the image inside the clip bounds to the given graphics object.
Rectangle clip = g.getClipBounds();
if (clip != null) {
    int w = image.getWidth();
    int h = image.getHeight();
    int x = Math.max(0, Math.min(clip.x, w));
    int y = Math.max(0, Math.min(clip.y, h));
    w = Math.min(clip.width, w - x);
    h = Math.min(clip.height, h - y);
...
voiddrawImageInOval(Graphics2D gr, Image img, Rectangle r, boolean noShrink)
draw an image in a rectangle
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);
...
RectangledrawImageInPolygon(Graphics g2d, BufferedImage img, Polygon poly, double xfactor, double yfactor)
draw Image In Polygon
int[] xPts = poly.xpoints, yPts = poly.ypoints;
int minXPt = xPts[0], minYPt = yPts[0], maxXPt = xPts[0], maxYPt = yPts[0];
for (int i = 1; i < poly.npoints; i++) {
    if (xPts[i] < minXPt)
        minXPt = xPts[i];
    if (yPts[i] < minYPt)
        minYPt = yPts[i];
    if (xPts[i] > maxXPt)
...
RectangledrawImageInRect(Graphics g2d, BufferedImage img, Rectangle rect, double xfactor, double yfactor)
draw Image In Rect
int panelWt = rect.width;
int panelHt = rect.height;
int x = rect.x + (int) (panelWt * xfactor);
int y = rect.y + (int) (panelHt * yfactor);
g2d.drawImage(img, x, y, null);
Rectangle imgRect = new Rectangle(x, y, img.getWidth(), img.getHeight());
return imgRect;