Hi Friends,
I want to make a Black&White image from a colored one (the format is JPG)
using Java2D!
Well, I'm using these lines of code to do it :
private ImageIcon prepareBnWImage(Image img, ImageObserver io)
{
int iw = img.getWidth(io);
int ih = img.getHeight(io);
BufferedImage srcImg = new BufferedImage(iw, ih,
BufferedImage.TYPE_INT_RGB);
Graphics2D srcG = srcImg.createGraphics();
RenderingHints rhs = srcG.getRenderingHints();
srcG.setRenderingHints(rhs);
srcG.drawImage(img, 0, 0, null);
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorConvertOp theOp = new ColorConvertOp(cs, rhs);
BufferedImage dstImg = new BufferedImage(iw, ih,
BufferedImage.TYPE_INT_RGB);
theOp.filter(srcImg, dstImg);
return( new ImageIcon(dstImg) );
}
Everything works great but the problem is that the picture has "transparent"
background. When I convert it to B&W pic, the background turns to BLACK and
gets very ugly! I want the background to remain transparent as it was.
Any solution ? Idea? Comment ?
Best Regards,
Armond
===========================================================================
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".