【发布时间】:2013-02-25 23:00:30
【问题描述】:
我知道如何用纯色填充 Swing 中的矩形:
Graphics2D g2d = bi.createGraphics();
g2d.setColor(Color.RED);
g2d.fillRect(0,0,100,100);
我知道如何用图像填充它:
BufferedImage bi;
Graphics2D g2d = bi.createGraphics();
g2d.setPaint (new Color(r, g, b));
g2d.fillRect (0, 0, bi.getWidth(), bi.getHeight());
但是如何用一些 100x100 的平铺图案填充 950x950 的矩形呢?
(图案图像应使用 100 次)
【问题讨论】:
-
将每个元素放入数组中(按正确的顺序),然后在数组中循环
-
为了更好的帮助,请尽快发布SSCCE,简短、可运行、可编译
-
您是否尝试过为此使用TexturePaint 对象?
-
@HovercraftFullOfEels 不,我不知道,谢谢!
标签: java swing graphics 2d design-patterns