tags:

views:

276

answers:

2

Hello!

I try to save the tiff instead of coloure gray-scaled. How could I do this? (JAI must be used, because it is a tiff!)

Thanks a lot in advance & Best Regards.

+2  A: 

What you want is to download the JAI Image I/O Tools, which provides ImageIO adapters for JAI. Once you've installed that, it's smooth sailing.

final BufferedImage in = ImageIO.read(new File("frabozzle.tif"));
final BufferedImage out = new BufferedImage(
    in.getWidth(), in.getHeight(),
    BufferedImage.TYPE_BYTE_GRAY);
out.getGraphics().drawImage(in, 0, 0, null);
ImageIO.write(out, "TIFF", new File("graybozzle.tif"));
Jonathan Feinberg
hmm, and how could I save the image without any compression grayscaled?
Tim
See my edit for one way.
Jonathan Feinberg
I get a Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6422430.It is in line out.getGraphics().
Tim
in = (java.awt.image.BufferedImage) BufferedImage@381d92; type = 0 ColorModel: #pixelBits = 32 numComponents = 1 color space = java.awt.color.ICC_ColorSpace@1d8e92 transparency = 1 alpha = false isAlphaPre = false sun.awt.image.SunWritableRaster@7e5130
Tim
Problem is solved. My image, but IrfanView displays it in red color. I do not know why, but I display it in other programs well, but not in GIMP :-(
Tim
+2  A: 

Given a BufferedImage, you can use the filter() method of ColorConvertOp, as shown in this example.

trashgod