Java Draw Image drawTiledImage(Rectangle2D bounds, Graphics2D g2, Image image, ImageObserver observer, int imageWidth, int imageHeight, int tilePadding)

Here you can find the source of drawTiledImage(Rectangle2D bounds, Graphics2D g2, Image image, ImageObserver observer, int imageWidth, int imageHeight, int tilePadding)

Description

draw Tiled Image

License

Open Source License

Declaration

public static void drawTiledImage(Rectangle2D bounds, Graphics2D g2, Image image, ImageObserver observer,
            int imageWidth, int imageHeight, int tilePadding) 

Method Source Code


//package com.java2s;

import java.awt.Graphics2D;
import java.awt.Image;

import java.awt.geom.Rectangle2D;

import java.awt.image.ImageObserver;

public class Main {
    public static void drawTiledImage(Rectangle2D bounds, Graphics2D g2, Image image, ImageObserver observer,
            int imageWidth, int imageHeight, int tilePadding) {
        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()) {
                h = (int) bounds.getMaxY() - y;
            }/*from  w w w .j ava2s .  co m*/
            for (int col = 0; col < cols; col++) {
                w = imageWidth;
                if ((x + imageWidth) > bounds.getMaxX()) {
                    w = (int) bounds.getMaxX() - x;
                }
                // no scaling
                g2.drawImage(image, x, y, x + w, y + h, 0, 0, w, h, observer);
                // move over a column
                x += w + tilePadding;
            }
            // go down a row
            y += h + tilePadding;
            x = (int) bounds.getX();
        }
    }
}

Related

  1. drawPixel(int x, int y, Color color, BufferedImage displayMap)
  2. drawScaledImage(Graphics graphics, BufferedImage image, int x, int y, int w, int h, int left, int right)
  3. drawScaledImage(Image image, Component canvas, Graphics g)
  4. drawSquare(BufferedImage image, int x, int y, int size, int pixel)
  5. drawStretchedImage(Rectangle2D bounds, Graphics2D g2, Image image, ImageObserver observer)
  6. drawTransparentImageInOval(Graphics2D gr, Image img, Rectangle r, boolean noShrink, double transparency)
  7. drawVerticalBar(final BufferedImage image, final double max, final double min)
  8. drawVerticalLineAt(int x, int dottedLine, Color color, BufferedImage displayMap)
  9. drawVolatileImage(Graphics2D g, VolatileImage volatileImage, int x, int y, Image orig)