你好我将图像从彩色转换为纯黑色和白色,结果是一个黑暗的图像.我没理由.以下是我的代码,它受到SO上其他代码的启发.
任何指导都会有所帮助.
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);
我没有得到我做错的事.使用任何其他开源库的任何更多想法都可以.
工作:::::
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"));
解决方法:
您实际上并没有将彩色图像转换为黑白图像;您正在创建一个与旧图像大小相同的新空白图像.您需要实际执行某些操作来处理旧图像.
标签:java,image-processing
来源: https://codeday.me/bug/1007/1864943.html