dcsimg
How to get R,G,B,A out of arbitrary BufferedImage implementations?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Matt_Mead
Posted On:   Monday, January 14, 2002 10:20 AM

I'm porting an image resampling algorithm to Java and using the JAI to perform input/output of images. I'd port the algorithm to the Interpolation abstraction, but the algorithm changes based on several things, and doesn't quite fit the abstraction. Anyway, I'm running into trouble with certain image formats. If I load a JPG, things work fine. However, if I load a PNG, things fail. The BufferedImage returned has a type of TYPE_CUSTOM ((int) 0). Its SampleModel is PixelInterleavedSampleModel, its ColorModel is ComponentColorModel. I've been using ColorModel.get{Red,Green,Blue,Alph} and/or getComponents but on PNG images these throw an exception because there is more than one component involved in getting the individual values.    More>>

I'm porting an image resampling algorithm to Java and using the JAI to perform input/output of images. I'd port the algorithm to the Interpolation abstraction, but the algorithm changes based on several things, and doesn't quite fit the abstraction.

Anyway, I'm running into trouble with certain image formats. If I load a JPG, things work fine. However, if I load a PNG, things fail. The BufferedImage returned has a type of TYPE_CUSTOM ((int) 0). Its SampleModel is PixelInterleavedSampleModel, its ColorModel is ComponentColorModel.


I've been using ColorModel.get{Red,Green,Blue,Alph} and/or getComponents but on PNG images these throw an exception because there is more than one component involved in getting the individual values.


How can I write code that will get the color values out of any BufferedImage to work with them?


Thanks!



-matt

   <<Less

Re: How to get R,G,B,A out of arbitrary BufferedImage implementations?

Posted By:   Christopher_Schultz  
Posted On:   Monday, January 14, 2002 11:36 AM

In the past, I've used a PixelGrabber (also defined in java.awt.image) to do things like this.



However, I went back into the API and can't remember exectly what I did with that class, since it looks like all you can do is get a big byte[] or int[] based on an image.



Perhaps you can hack around and see if this will help you.



Good luck,

-chris
About | Sitemap | Contact