【发布时间】:2014-01-07 10:08:38
【问题描述】:
我想为我拥有的 BufferedImage 的一个子区域着色。我目前正在做:
public BufferedImage paintSubImage(BufferedImage img, int x, int y, int w, int h) {
Graphics g = img.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(x,y,w,h);
return img;
}
但是我不能给它上色。我做错了吗?
【问题讨论】:
-
我觉得不错。发布您的
SSCCE来演示问题,以便我们可以看到您在部分绘制后如何使用 BufferedImage 的上下文。 -
@camickr:这个方法会改变我传递的原始 BufferedImage 对象还是返回未着色的 BufferedImage?
-
会改变原来的BufferedImage。
-
但是你可能需要
dispose的Graphics上下文 -
Given the fact that there is little or no context to go on, it's difficult to know exactly what's wrong.- 这就是为什么要求 OP 获得 SSCCE。显然这个问题对 OP 来说并不太重要,因为他有足够的时间来创建和发布 SSCCE。
标签: java awt bufferedimage