Jump to content
  • Advertisement
Sign in to follow this  
kuroioranda

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

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

If you intended to correct an error in the post then please contact us.

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;

	public LoadImage(String filename)
	{
		try 
		{
			image = ImageIO.read(new File(filename));
			
			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!

Share this post


Link to post
Share on other sites
Advertisement
Just wanted to let everyone know that I found the solution to the problem. It turns out that VolatileImages were added almost exclusively for the benefit of hardware accelerated back buffers, and that a BufferedImage, if the surface format matches a hardware-based target surface, will automatically be moved into a video-accelerated buffer whenever possible.

So I tried it, and it works like a charm.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!