私はcombit.imageioimpl.plugins.tiff.TIFFPackBitsCompressorを使用して、PackBitsを使用しているtiffバイトの配列をエンコードしようとしています。私はこのクラスに慣れておらず、使用方法に関する多くの例を見つけていません。しかし、javadocに従うと、データをエンコードしようとするたびにNPEを取得しています。私が見る限りでは、私の価値のどれもがヌルです。私は、この時点で複数の値を持つこれらのテストを試してみましたが、以下の私の最も最近の反復できました: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'にキャストすると、コンプレッサーのインスタンスをparamに渡すこともできますが、これはプラグインが知らないカスタム圧縮にはもっと便利です。 – haraldK