here에 설명 된대로 BufferedImage
클래스의 각 픽셀의 파란색 부분을 반전하는 알고리즘을 BufferedImageOp
클래스를 사용하여 구현하려고합니다. 내 시도는이 방법의 생성 결과 :BufferedImageOp.filter() Throwing Channel Errors
private BufferedImage getInvertedVersion(BufferedImage source) {
short[] invert = new short[256];
short[] straight = new short[256];
for (int i = 0; i < 256; i++) {
invert[i] = (short)(255 - i);
straight[i] = (short)i;
}
short[][] blueInvert = new short[][] { straight, straight, invert }; //Red stays the same, Green stays the same, Blue is inverted
BufferedImageOp blueInvertOp = new LookupOp(new ShortLookupTable(0, blueInvert), null);
//This produces error #1 when uncommented
/*blueInvertOp.filter(source, source);
return source;*/
//This produces error #2 instead when uncommented
/*return blueInvertOp.filter(source, null);*/
}
을하지만, 나는 내 BufferedImageOp
클래스의 .filter 메서드를 호출 할 때 채널 또는 바이트 수와 관련된 오류를 받고 있어요.
오류 # 1 :
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Number of channels in the src (4) does not match number of channels in the destination (2)
at java.awt.image.LookupOp.filter(LookupOp.java:273)
at java.awt.image.LookupOp.filter(LookupOp.java:221)
오류 # 2 :
이Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Number of color/alpha components should be 4 but length of bits array is 2
at java.awt.image.ColorModel.<init>(ColorModel.java:336)
at java.awt.image.ComponentColorModel.<init>(ComponentColorModel.java:273)
at java.awt.image.LookupOp.createCompatibleDestImage(LookupOp.java:413)
링크의 코드는 매우 오래
, (이 기록 된 코드의 주석 부분은 위의 이러한 각각의 오류를 발생 1998 년에!) 그래서 나는 그때부터 코드가 더 이상 작동하지 않는 이유가 무엇인가가 바뀌 었다고 가정합니다. 그러나, 나는 개념을 거의 설명하는 또 다른 출처를 찾을 수 없었다. 이것은 나의 가장 중요한 관심사이다.
누구든지이 오류의 의미와 해결 방법을 설명 할 수 있습니까? 또는 더 나은 방법은 이미지를 조작하는 방법에 대한 최신 정보를 제공하지만 여전히 철저한 자습서입니다.