有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

带图像的java fillRect方法

我试图使用Java中的fillRect方法来用图像填充矩形。有没有办法用fillRect方法来做这件事

以下是我正在编写的代码:

    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, );
    }

共 (1) 个答案

  1. # 1 楼答案

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

    没有

    取而代之的是,在查看区域的宽度和高度上平铺图像。要获得仅适用于特定矩形的效果,请将该矩形设置为剪辑(在平铺之前)