我正在尝试生成自定义纹理,目前我想创建一个农田
我创建了一个spica-image,现在想要在我的缓冲图像上绘制它
bufferedImage.drawImage(baseImage, (int) x, (int) y, paintWidth, paintHeight, null);目前,它需要49196乘以5632ms。
有没有可能提高速度,因为它总是绘制相同的图像?
发布于 2015-02-15 02:32:32
我认为你做了什么::
让我们首先看看你在做什么(据我所知)如下所示。
BufferedImage background = ...
int totalWidth = background.getWidth();
int totaleight = background.getHeight();
BufferedImage pattern = ....
int patternWidth = patternImage.getWidth();
int patternHeight = patternImage.getHeight();
Graphics2D g = background.createGraphics();
for (int y = ... ; y < totalHeight; y += patternHeight) {
for (int x = ...; x < totalWidth; x += patternWidth) {
g.drawImage(pattern, x, y,
patternWidth, patternHeight, null);
}
}
g.dispose();现在你想提高速度。绘制的图像不需要缩放;宽度和高度精确。可能昂贵的是模式的RGBA格式到后台Graphics2D的RGBA格式的转换。
如果这还不能解决问题,可以使用WritableRaster和RasterOp。
java提供了什么
仅此用例就有TexturePaint。参见here。
我仍然有一些疑问:模式图像的大小(可以制作一个2x2的模式),TexturePaint是否可以做到更优。像素格式可能非常关键。
https://stackoverflow.com/questions/28518424
复制相似问题