本文介绍了将图像转换为黑白(不是灰度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我将图像从彩色转换为纯黑白,结果是暗图像。我没理由。以下是我的代码,它受到SO上其他代码的启发。
任何指导都会有所帮助。
hello I am converting an image from color to pure black and white the result is a dark image. I am not getting the reason. Following is my code its been inspired by other codes on SO.Any guidance would be helpfull.
BufferedImage coloredImage = ImageIO.read(new File("/home/discusit/ninja.png"));
BufferedImage blackNWhite = new BufferedImage(coloredImage.getWidth(),coloredImage.getHeight(),BufferedImage.TYPE_BYTE_BINARY);
Graphics2D graphics = blackNWhite.createGraphics();
graphics.drawImage(blackNWhite, 0, 0, null);
我没有得到我做错的事。使用任何其他开源库的任何更多想法都可以。
I am not getting what I am doing wrong. Any more ideas using any other open source library would be fine.
工作:::::
BufferedImage coloredImage = ImageIO.read(new File("/home/abc/ninja.png"));
BufferedImage blackNWhite = new BufferedImage(coloredImage.getWidth(),coloredImage.getHeight(),BufferedImage.TYPE_BYTE_BINARY);
Graphics2D graphics = blackNWhite.createGraphics();
graphics.drawImage(coloredImage, 0, 0, null);
ImageIO.write(blackNWhite, "png", new File("/home/abc/newBlackNWhite.png"));
推荐答案
您实际上并未将彩色图像转换为黑色和白色;您正在创建一个与旧图像大小相同的新空白图像。你需要实际做一些事来处理旧图像。
You don't actually convert the colored image to black and white; you're creating a new, blank image the same size as the old one. You need to actually do something to process the old image.
这篇关于将图像转换为黑白(不是灰度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!