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

voiddrawSquare(BufferedImage image, int x, int y, int size, int pixel)
draw Square
for (int px = 0; px < size; ++px) {
    for (int py = 0; py < size; ++py) {
        image.setRGB(x + px, y + py, pixel);
voiddrawStretchedImage(Rectangle2D bounds, Graphics2D g2, Image image, ImageObserver observer)
draw Stretched Image
drawStretchedImage(bounds, g2, image, observer, false);
voiddrawTiledImage(Rectangle2D bounds, Graphics2D g2, Image image, ImageObserver observer, int imageWidth, int imageHeight, int tilePadding)
draw Tiled Image
int x = (int) bounds.getX();
int y = (int) bounds.getY();
int w = imageWidth;
int h = imageHeight;
int cols = (int) Math.ceil(bounds.getWidth() / imageWidth);
int rows = (int) Math.ceil(bounds.getHeight() / imageHeight);
for (int row = 0; row < rows; row++) {
    if ((y + imageHeight) > bounds.getMaxY()) {
...
voiddrawTransparentImageInOval(Graphics2D gr, Image img, Rectangle r, boolean noShrink, double transparency)
draw an image in a rectangle
Composite oldComposite = gr.getComposite();
gr.setComposite(oldComposite);
Composite newComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) transparency);
gr.setComposite(newComposite);
drawImageInOval(gr, img, r, noShrink);
gr.setComposite(oldComposite);
voiddrawVerticalBar(final BufferedImage image, final double max, final double min)
draw Vertical Bar
final int height = image.getHeight();
final Graphics2D g = image.createGraphics();
final FontMetrics metrics = g.getFontMetrics(g.getFont());
final int x = image.getWidth() - 1 - BAR_SIZE_VERT;
final double middle = (max + min) / 2.0;
final double quarter = (max - middle) / 2.0;
final int width = image.getWidth();
for (int y = 0; y < height; y++) {
...
voiddrawVerticalLineAt(int x, int dottedLine, Color color, BufferedImage displayMap)
draw Vertical Line At
for (int y = 0; y < displayMap.getHeight(); y += dottedLine) {
    drawPixel(x, y, color, displayMap);
VolatileImagedrawVolatileImage(Graphics2D g, VolatileImage volatileImage, int x, int y, Image orig)
From The Java Developers Almanac 1.4
e674.
final boolean VERBOSE = false;
final int MAX_TRIES = 5;
for (int i = 0; i < MAX_TRIES; i++) {
    if (VERBOSE) {
        System.out.println("try " + (i + 1));
    if (volatileImage == null) {
        final int imageWidth = orig.getWidth(null);
...