我正在尝试实现一些java代码,可以帮助根据PNG图像的某些特征调整PNG图像:例如颜色允许解释类型位深度
0 1,2,4,8,16 每个像素都是一个灰度样本。
从中我搜索到如果颜色类型为0,我应该根据不同的位深度来实现代码:1、2、4、8、16,用于灰度。
我想使用 Graphic2D 库,所以我认为:
if (img_bitDepth == 16) {
type = BufferedImage.TYPE_USHORT_GRAY; // 11
} else if (img_bitDepth == 8) {
type = BufferedImage.TYPE_BYTE_GRAY; //10
} else if (img_bitDepth == 4) {
type = BufferedImage.TYPE_BYTE_BINARY;
} else if (img_bitDepth == 2) {
type = BufferedImage.TYPE_BYTE_BINARY;
} else if (img_bitDepth == 1) {
type = BufferedImage.TYPE_BYTE_BINARY;
} else {
//logger warning.
}
BufferedImage resizedImage = new BufferedImage (img_width, img_height, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, img_width, img_height, null);
g.dispose();
但我不知道如何使用图像类型“TYPE_BYTE_BINARY”设置 2 和 4 的位深。
有什么建议吗?