您好,我正在将图像从彩色转换为纯黑白,结果是深色图像。我不明白原因。以下是我的代码,它受到 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"));