First off you’ll have to be using 1.4, otherwise you won’t be able to take advantage. Secondly have a look for VolatileImage, which is stored only in vRam and which you need to do management of image loss manually. However there are a couple of snafus that may trip you up with volative images, namely i dont think you can do any sort of transparency :o
There’s also ‘AutomaticImages’ which are regular BufferedImages which the VM will attempt to cache in vRam, and handle management itself. With the correct massaging you can also get these to have 1-bit transparency and still be hardware accelerated.
A code snippit from my (now on permanent hold, :-[ ) Phoenix project:
/** Loads image, creates automatic image/buffered image and copies it into it.
* Currently only tested with gifs, so undefined if any other file path is passed to it.
*/
public BufferedImage loadImage(String filename, boolean solid)
{
// Load image from file.
Image tempImage = new ImageIcon(filename).getImage();
BufferedImage sprite = null;
// Get dimensions of image
int spriteW = tempImage.getWidth(null);
int spriteH = tempImage.getHeight(null);
if (spriteW != -1)
{
// If a solid tile, load as such. Otherwise use bitmask transparency
if (solid)
sprite = graphicsConfig.createCompatibleImage(spriteW, spriteH, Transparency.OPAQUE);
else
sprite = graphicsConfig.createCompatibleImage(spriteW, spriteH, Transparency.BITMASK);
// Copy from Image to BufferedImage
Graphics2D g = (Graphics2D)sprite.getGraphics();
g.drawImage(tempImage, null, null);
g.dispose();
}
else
{
System.out.println("Error loading images: " + filename + " not found");
}
return sprite;
}
Jeff et al, if you’re reading this - how long until we see a full site with the articles section up again?