开发者

Java / JAI - save an image gray-scaled

开发者 https://www.devze.com 2022-12-19 02:14 出处:网络
I try to save the tiff instead of coloure 开发者_StackOverflow中文版gray-scaled. How could I do this? (JAI must be used, because it is a tiff!)

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

Thanks a lot in advance & Best Regards.


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"));


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

0

精彩评论

暂无评论...
验证码 换一张
取 消