I am attempting to create a mosaic of images in Java. I calculate the size of the new image I'm creating, and then for each subimage that will be part of the mosaic, I do a paint call.
In pseudocode:
create buffered image big enough to hold entire mosaic
create Graphics2D context from that image
for each buffered subimage that will be a part of the mosaic
draw the subimage on the graphics context of big bufferedimage
g2.drawImage(myImage, x,y,width,height,null,null)
Is there a better way to do this? I'd hope there's some sort of direct copying operation available, since I don't want to transform or scale the subimages into the bigger image. Something akin to an arraycopy of the rasters of each subimage. I notice there's a setData method that takes in a Raster object, but the method notes that the Raster has to be in same coordinate space.
Any thoughts? This is a bit of a bottleneck in my program and I'd like it to be as fast as possible.
EDIT: It turns out I was wrong (as is often the case when assumptions are made without hard data) about where the bottleneck was. I had a bug where multiple 3MB pictures were being read over and over again rather than using the scaled down versions of the images cached in memory. My running time went from 50 minutes to 15 seconds when I made the fix.