在java中使用BuffereImage创建磁贴

在java中使用BuffereImage创建磁贴,java,hexagonal-tiles,Java,Hexagonal Tiles,代码的要点是创建一个2x2的图像平铺,在2x2网格中以较小的尺寸复制相同的图像。我想更新图片,以便我可以打印到jpanel上。我得到的只是黑色的图像。谁能告诉我密码有什么问题吗。或者告诉我如何创建更好的代码 我想制作四个较小的原始图像,并将其放置在与原始图像大小相同的2x2网格中 类似于 public static BufferedImage split(BufferedImage img) { BufferedImage pic = new BufferedImage(img.getWi

代码的要点是创建一个2x2的图像平铺,在2x2网格中以较小的尺寸复制相同的图像。我想更新图片,以便我可以打印到jpanel上。我得到的只是黑色的图像。谁能告诉我密码有什么问题吗。或者告诉我如何创建更好的代码


我想制作四个较小的原始图像,并将其放置在与原始图像大小相同的2x2网格中

类似于

public static BufferedImage split(BufferedImage img) {
   BufferedImage pic = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
   Graphics g = pic.getGraphics();

    int width = 2000/2;
    int height = 2000/2;
    int imageW = pic.getWidth();
    int imageH = pic.getHeight();
                // Tile the image to fill our area.
    for (int x = 0; x < width; x += imageW) {
        for (int y = 0; y < height; y += imageH) {
            g.drawImage(pic, x, y, null);
        }
    }  
    return pic ;  
}  

您可能还想了解有关如何改进缩放算法的更多详细信息;?你在自己画这张照片?我不知道我明白你想做什么。你拍摄了一幅图像,你创建了另一幅同样大小的图像,你想把第一幅图像画成第二幅图像,并且给定的间隔是1:1。。。??第二张图像不应该更大/更小,还是原始图像应该缩放?我想制作四张更小的原始图像,并将其放置在与原始图像大小相同的2x2网格中。是的。你能解释一下这段代码中发生了什么吗。请我真的很想知道,这是非常基本的。它创建一个与img大小相同的新BuffereImage。然后创建原始对象的缩放实例,将其减少0.25%。然后将缩放实例绘制到picImage scaled=img.getScaledInstancewidth,height,Image.SCALE\u SMOOTH;可以非常感谢你的帮助。非常感谢。
public static BufferedImage split(BufferedImage img) {
    BufferedImage pic = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics g = pic.getGraphics();

    int width = pic.getWidth() / 4;
    int height = pic.getHeight() / 4;

    Image scaled = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);

    // Tile the image to fill our area.
    for (int x = 0; x < pic.getWidth(); x += width) {
        for (int y = 0; y < pic.getHeight(); y += height) {
            g.drawImage(scaled, x, y, null);
        }
    }
    g.dispose();
    return pic;
}