Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > grayscale BufferedImage from any imagetype with jai api

Thread Tools

grayscale BufferedImage from any imagetype with jai api

Posts: n/a
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 ,
public BufferedImage makeMyGrayImage(String imagename){
RenderedImage im0=JAI.create("fileload",imagename);
Raster rastPic = im0.getData();
int widthPix = rastPic.getWidth();
int heightPix = rastPic.getHeight();

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;
orig=new BufferedImage(widthPix, heightPix,??);



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

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
jai to create a grayscale img from any imagetype harryos Java 0 07-18-2008 08:34 PM
Acquire grayscale USB Video and save as a sequence of 8-bit grayscale bitmaps Speed C++ 5 03-11-2007 04:22 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
problem with creating JAI grayscale image Java_New Java 5 05-27-2006 03:24 PM
problem using JAI bilinear interpolation to scale a bufferedimage Raj Java 2 11-25-2003 11:52 AM