Reputation: 14863
I i'm trying to generate custom textures, at the moment i want to create a farmland
i created an spica-image and now want to paint it on my buffered-image
bufferedImage.drawImage(baseImage, (int) x, (int) y, paintWidth, paintHeight, null);
at the moment it takes for 49196 times 5632ms.
Is it possible to improve the speed since it paints always the same image?
Upvotes: 0
Views: 447
Reputation: 109547
What I think you did:
Let's first look at what you are doing something (as far as I understand) like below.
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();
Now you want to improve the speed. The drawn image should need no scaling; width and height exact. What might be costly is the conversion of RGBA format of the pattern to RGBA format of the background Graphics2D.
If that does not help, one could use WritableRaster and RasterOp.
What java provides
There is TexturePaint for just this use-case. See here.
I still have some doubts: size of the pattern image (one could make a 2x2 pattern), whether TexturePaint can be that more optimal. The pixel format can be very decisive.
Upvotes: 2