grayscale BufferedImage from any imagetype with jai api

H

harryos

hi
i have an input image that may be truecolor png or grayscale pgm.I
need to create a grayscale BufferedImage out of it.I found that std
java imageio doesn't support pgm format so i tried the jai api.I am
not very sure how to create a grayscale BufferedImage out of it.I
think i need to check the color_type of incoming image and if
Truecolor ,i will have to apply the ColorConvertOp.

i tried the following ,
<code>
public BufferedImage makeMyGrayImage(String imagename){
RenderedImage im0=JAI.create("fileload",imagename);
Raster rastPic = im0.getData();
int widthPix = rastPic.getWidth();
int heightPix = rastPic.getHeight();
....

</code>
this works for both truecolor png and grayscale pgm images.I am not
very sure how to create a BufferedImage out of it .what should i give
as the imageType if the image is truecolor? i have put a ?? for that
argument..someone pls help me here

BufferedImage orig;
if(im0.getProperty("color_type")=="Truecolor"){
orig=new BufferedImage(widthPix, heightPix,??);

}

orig.setData(rastPic);

will this create a proper BufferedImage?
If i have this ,then i think i can apply the ColorConvertOp and
create a grayscale BufferedImage

I am quite a newbie with jai and java imageprocessing ..couldn't find
many example code to learn from.if the above is not the correct way to
do this,pls advise

thanks
harry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top