grayscale BufferedImage from any imagetype with jai api

Discussion in 'Java' started by harryos, Jul 19, 2008.

  1. harryos

    harryos Guest

    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
    harryos, Jul 19, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry Simpson

    Transform 24bit BMP to grayscale??

    Harry Simpson, Oct 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    656
    Harry Simpson
    Oct 30, 2003
  2. Raj
    Replies:
    2
    Views:
    1,856
  3. Java_New
    Replies:
    5
    Views:
    2,952
    Andrey Kuznetsov
    May 27, 2006
  4. Speed
    Replies:
    5
    Views:
    405
    Speed
    Mar 11, 2007
  5. harryos
    Replies:
    0
    Views:
    420
    harryos
    Jul 18, 2008
Loading...

Share This Page