• 14
• 12
• 9
• 10
• 13

# [java] Copying alpha from a Buffered Image to a Volatile Image?

This topic is 3939 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm currently writing a map editing tool in Java for a game project I'm working on. I'm trying to use accelerated (or at least image format compatible) images for speed purposes. I initially load my image into a BufferedImage with ImageIO.read(), and then blit that onto a VolatileImage object using drawImage. This works fine for all of the color channels, but the alpha channel isn't actually getting copied to the VolatileImage as far as I can tell. I have verified (by drawing the BufferedImage to my target surface) that the alpha channel is indeed being loaded correctly from the png file. I have also verified that the VolatileImage has been created with transparency support. So it appears that the alpha channel is only used to modify the blending of the color channels on the target surface, and the alpha values themselves are not updated. Here is the code that creates both of the images (sans the class stuff around it):

BufferedImage image;
VolatileImage acceleratedImage;

{
try
{

if(image.getColorModel().hasAlpha())
System.out.println("Alpha");
}
catch(Exception e)
{
e.printStackTrace();
}
}

public Image getAcceleratedImage(GraphicsConfiguration graphicsConf)
{
if(acceleratedImage == null)
{
acceleratedImage =
graphicsConf.createCompatibleVolatileImage(image.getWidth(), image.getHeight(), Transparency.TRANSLUCENT);
acceleratedImage.createGraphics().drawImage(image, 0, 0, null);

if(acceleratedImage.getTransparency() == Transparency.TRANSLUCENT)
System.out.println("translucent");
}

if(acceleratedImage.contentsLost())
{
acceleratedImage.createGraphics().drawImage(image, 0, 0, null);
}

return acceleratedImage;
}


Any help would be fantastic!