Hi Ed,

  Maybe this could help you.
  There should be better ways of doing that but at least it works. ;-)

  Regards,
    Nuno

--------------
  public void grayscale() {

    BufferedImage bi = getSourceImage(); // getBufferedImage();
    int width = bi.getWidth() ;
    int height = bi.getHeight() ;
    int type = bi.getType() ;

    BufferedImage grayBi = new BufferedImage(width, height,
BufferedImage.TYPE_BYTE_GRAY);
    Graphics g = grayBi.getGraphics();

    g.drawImage(bi, 0, 0, null);
    bi = null ;

    // put grayscale image back to the same image type
    BufferedImage bf = new BufferedImage(width, height,type);
    bf.getGraphics().drawImage(grayBi, 0, 0, null);

    setSourceImage(bf,true);

    // free resources allocated
    g.dispose();
    g = null ;
    grayBi = null ;
  }
-----------

----- Original Message -----
From: "Ed Brown" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 14, 2002 5:36 PM
Subject: [JAVA2D] gray-scale conversion


> Can anyone help.
>
> I am loading a series of color JPEG images using the codec
> classes.
> Once loaded I wish to convert the BufferedImage to a gray-scale
> image before performing operations on it.
>
> Can anyone tell be the most straightforward way to go about this.
>
> Thanks
> Ed Brown
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff JAVA2D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to