com.sun.media.imageioimpl.plugins.tiff.TIFFPackBitsCompressor를 사용하여 PackBits를 사용하는 tiff 바이트 배열을 인코딩하려고합니다. 나는이 수업에 익숙하지 않고 그것을 사용하는 방법에 대한 많은 예제를 발견하지 못했다. 그러나 javadoc을 따라갈 때마다 데이터 인코딩을 시도 할 때마다 NPE를 얻었습니다. 지금까지 내가 볼 수있는 한, 내 가치 중 하나도 null입니다. 나는이 시점에서 여러 값으로 테스트를 해봤지만 아래에있는 내 가장 최근의 반복은 다음과 같습니다TIFFPackBitsCompressor - NPE?
TIFFPackBitsCompressor pack = new TIFFPackBitsCompressor();
//bImageFromConvert is a 16-bit BufferedImage with all desired data.
short[] bufferHolder = ((DataBufferUShort) bImageFromConvert.getRaster().getDataBuffer()).getData();
//Since bImageFromConvert is 16-bits, the short array isn't the right length.
//The below conversion handles tihs issue
byte[] byteBuffer = convertShortToByte(bufferHolder);
//I'm not entirely sure what this int[] in the parameters should be.
//For now, it is a test int[] array containing all 1s
int[] testint = new int[byteBuffer.length];
Arrays.fill(testint, 1);
//0 offset. dimWidth = 1760, dimHeight = 2140. Not sure what that last param is supposed to be in layman's terms.
//npe thrown at this line.
int testOut = pack.encode(byteBuffer, 0, dimWidth, dimHeight, testint, 1);
사람이 무슨 일이야에 관해서는 어떤 통찰력을 가지고 있습니까? 또한, 가능하다면 누구든지 Java 프로그램에서 PackBits를 사용하여 TIFF 파일을 인코딩하는 더 좋은 방법을 알고 있습니까?
제 질문을 명확하게 해줄 수 있는지 알려주세요.
감사합니다.
스택 트레이스는 어디에 있습니까? 어쨌든, 나는 당신이 압축기를 직접 사용한다고 생각하지 않는다. 대신에 ImageWriteParam에서 압축 유형으로 "PackBits"를 지정할 때 JAI ImageIO TIFF 플러그인 ('TIFFImageWriter')이 사용한다. 'TIFFImageWriteParam'로 먼저 캐스팅하면, 압축기 인스턴스를 매개 변수로 전달할 수 있습니다. 그러나 이것은 플러그인이 알지 못하는 사용자 정의 압축에 더 유용합니다. – haraldK