I think the main problem is that the large image isn't getting hardware accelerated. It can't be stored in video memory because it's too large. Try changing it to something no larger than 1024x768. Assuming you can view that resolution on your screen and have an adequate video card, it will probably be much faster if I'm right.
There is probably some way to load the image in chunks without storing it in a larger image. javax.imageio.ImageReader has something involving tiles, which makes me think it supports this capability. I'm not sure how it works though.
If you figure out how to use javax.imageio.ImageReader in this manner, I would appreciate it if you posted the code. I'm a bit curious about it.
There are a couple minor things I noticed. First, your drawImage method should call dispose() on the Graphics context after you finished drawing the image. I doubt that is causing the problem, but dispose should free up some kind of resources.
Second, you could optimize the loops that split the image up into tiles by reducing the multiplications to additions. This probably won't make enough of a difference, but it something I would always do with multiplications in an inner loop. Here's some code to explain what I mean:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| int iFrame = 0; int yOffsetInSourceImage = top; for (int y = 0; y < rows; ++y) { int xOffsetInSourceImage = left;
for (int x = 0; x < columns; ++x) { bframes[iFrame] = createImageResource(sheetImage, Transparency.BITMASK, width, height, xOffsetInSourceImage, yOffsetInSourceImage);
iFrame++; xOffsetInSourceImage += width; }
yOffsetInSourceImage += height; } |
I believe that is correct unless I'm interpreting some of your variables wrong.
Addition is a bit faster than multiplication, though this optimization would probably have a neglible effect. It might even slow things down if it prevents some other memory from being cached by the CPU.