【发布时间】:2011-02-18 13:05:41
【问题描述】:
我正在尝试在
中使用 QuantizeFilterhttp://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。干杯
【问题讨论】:
标签: java image image-processing quantization