【发布时间】:2015-10-27 12:19:36
【问题描述】:
我正在尝试实现一些 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 的位深。
有什么建议吗?
【问题讨论】: