0

编码:

private BufferedImage performBinary(BufferedImage original) {
    int step = 127;
    int min = 0;
    int max = 1;
    Raster originalRaster = original.getData();

    BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(),
            BufferedImage.TYPE_BYTE_BINARY);
    WritableRaster resultRaster = result.getRaster();
    for (int x = 0; x < originalRaster.getWidth(); x++) {
        for (int y = 0; y < originalRaster.getHeight(); y++) {
            int pix = originalRaster.getPixel(x, y, (int[]) null)[0];
            if (pix < step) {
                resultRaster.setPixel(x, y, new int[] { min });
            } else {
                resultRaster.setPixel(x, y, new int[] { max });
            }
        }
    }
    return result;
}
...
ImageIO.write(result, "jpg", new File(pathToFile));
...

问题:我将此结果保存到图像文件中,图像是我想要的黑白图像,但它具有 24 位深度。我想要黑白 1 位深度。我在 BufferedImage、ColorModel 和 ColorSpace 上阅读了 Javadoc,但不明白如何在输出上获得 1 位。帮我

4

0 回答 0