문제

에서 양자화 필터를 사용하려고합니다.

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 );
.

그러나 내가 왼쪽으로 남은 것은 다음과 같습니다 :

원래 IMG :

여기에 이미지 설명

양자화 된 IMG :

여기에 이미지 설명

문제점의 또 다른 분석은 inpixels 배열이 잘못 채워집니다. 원본 이미지의 3 분의 1에 3 번 충전됩니다.

어떤 포인터를 고칠 수있는 방법

또한 Java의 + 링크 + 빠른 양자화 알고리즘은 무엇입니까? 내가 검색하는 것은 type_int_bgr 이미지를 가져 와서 새로운 type_int_bgr 이미지를 생성하지만 픽셀 단위의 실제 차이가 적어 쉽게 볼 수 있습니다. 예를 들어, 255, 255, 234와 같은 값과 255, 255, 236과 같은 값을 갖는 값이 255,255,240으로 변환되어야한다. 건배

도움이 되었습니까?

해결책

The following example will convert your image correctly:

QuantizeFilter q = new QuantizeFilter();
int [] inPixels = new int[image.getWidth()*image.getHeight()*3];
int [] outPixels = new int[image.getWidth()*image.getHeight()*3];
image.getRaster().getPixels( 0, 0, image.getWidth(), image.getHeight(), inPixels );
q.quantize(inPixels, outPixels, image.getWidth(), image.getHeight(), 64, false, false);
WritableRaster raster = (WritableRaster) image.getData();
raster.setPixels(0,0,width,height,outPixels);

Also there is no reason to create the files implicitly, as ImageIO.write creates them automatically.

다른 팁

I have had the same problem and its not the code you posted that's at fault it's the QuantizeFilter class which doesn't go through all the pixels. You need to find this code part

 if (!dither) {
        for (int i = 0; i < count; i++)
            outPixels[i] = table[quantizer.getIndexForColor(inPixels[i])];

and multiply count by 3.

Please note that this is only a a fix if the last 2 parameters are set to false.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top