DonaEb
DonaEb

Reputation: 1

fillRect method with image

I am trying to use the fillRect method in Java to fill a rectangle with an image. Is there a way to do it using the fillRect method?

Here is the code I was working on:

    private int x = 0;
    private int y = 0;
    static int WIDTH = 1; 
    static int HEIGHT = 1; 
    private Image image = new ImageIcon("Golf_green.png").getImage();

    public BackGround() {
        WIDTH = 30;
        HEIGHT = 30;
    }

    public void paint(Graphics2D g) {
        g.drawImage(image, x, y, WIDTH, HEIGHT, "BLACK", , arg7, arg8, );
    }

Upvotes: 0

Views: 664

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168825

(fill rect with tiled image) is there a way to do it using the fillrect method?

No.

Instead, tile the image across the width and height of the viewing area. To get the effect that it is only for a particular rectangle, set that rectangle as the clip (prior to tiling).

Upvotes: 2

Related Questions