我正在尝试使用 QuantizeFilter
http://www.jhlabs.com/ip/filters/index.html
以减少屏幕截图的颜色深度。
这是我非常非常简单的代码:
Robot robo = new Robot();
BufferedImage notQuantized = robo.createScreenCapture( new Rectangle ( 0, 0, 300, 300 ) );
BufferedImage Quantized = new BufferedImage( 300, 300, BufferedImage.TYPE_INT_BGR);
File nonquantized = new File ("C:\\nonquantized.png");
File quantized = new File("C:\\quantized.png");
nonquantized.createNewFile();
quantized.createNewFile();
QuantizeFilter bla = new QuantizeFilter();
int [] outPixels = new int[300*300*3];
int [] inPixels = new int[300*300*3];
notQuantized.getRaster().getPixels( 0, 0, 300, 300, inPixels );
bla.quantize( inPixels, outPixels, 300, 300,2, true, true );
Quantized.getRaster().setPixels( 0, 0, 300, 300, outPixels );
ImageIO.write( Quantized, "png", quantized );
ImageIO.write( notQuantized, "png", nonquantized );
但是,我剩下的是:
原图:
量化的图像:
进一步分析问题表明,inPixels数组填充错误;它用原始图像的上三分之一填充了三次。
有什么指示我可以解决这个问题吗?
另外,Java中的任何链接都很好+快速量化算法?我搜索的是一种算法,它将采用 TYPE_INT_BGR 图像并生成新的 TYPE_INT_BGR 图像,但像素的实际差异较小,因此可以很容易地放气。
例如,如果我们在原始图像中有两个像素,其值为 255、255、234,另一个像素值为 255、255、236,则它们都应转换为 255,255,240。干杯