dcsimg
java.awt.Image get data
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Stanislav_Davydov
Posted On:   Thursday, September 19, 2002 09:24 AM

Hello!



Is it possible to retrieve byte array data with image pixels from any java.awt.Image object?




Best regards,
Stanislav

Re: java.awt.Image get data

Posted By:   Christopher_Schultz  
Posted On:   Thursday, September 19, 2002 11:01 AM

What you want is called a Pixel Grabber (java.awt.image.PixelGrabber). A simple usage is this:



Image image = ...;

int[] pixels = new int[image.getWidth() * image.getHeight()];

new PixelGrabber(image,
0, // Upper-left coordinate (x)
0, // Upper-left coordinate (y)
image.getWidth(),
image.getHeight(),
pixels,
0, // Offset
image.getWidth())
.grabPixels();



Your pixels array should now contain all the pixel values in ARGB format (1 byte each, with the alpha value being in the most-significant byte).



There's pretty much the exact same example in the class documentation. Check it out for more information.



Hope that helps,

-chris
About | Sitemap | Contact