Re: [Gdcm2] Java: pass an image for decompression as byte data
Cross-platform DICOM implementation
Brought to you by:
malat
|
From: Mathieu M. <mat...@gm...> - 2022-11-10 07:23:50
|
Hi,
On Wed, Nov 9, 2022 at 7:52 PM Mikhail Timofeev <mt...@ou...> wrote:
>
> Hi all,
> I am trying to create a program similar to the Examples/Java/DecompressImage but with the difference that I would like to read in the file in Java and pass the byte data to gdcm for decompression, ideally avoiding having to copy the data. Anyway here is my naive approach (which does not work):
>
> ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();
> change.SetTransferSyntax( new TransferSyntax(TransferSyntax.TSType.ImplicitVRLittleEndian) );
>
> byte[] bytes = Files.readAllBytes( Paths.get(file1));
>
> DataElement dataElementIn = new DataElement();
> dataElementIn.SetArray( bytes, bytes.length );
> Bitmap bitmap = new Bitmap();
Do not create your own Bitmap, this is a subclass of Object and is not
well supported in the swig wrapping.
Simply re-use the one from the ImageChangeTransferSyntax, eg:
Bitmap bitmap = change.GetOutput();
> bitmap.SetDataElement( dataElementIn );
> change.SetInput( bitmap );
>
> if( !change.Change() )
> {
> throw new Exception("Could not change: " + file1 );
> }
> Bitmap image = change.GetOutput();
>
> There are multiple issues here I suppose. But the actual error is this one thrown in the very last line:
>
> terminate called after throwing an instance of 'std::bad_cast'
> what(): std::bad_cast
>
> Does anybody have any hints how proceed with this? Or maybe even an example of how this should be properly done?
> Thanks and best regards
> MT
> _______________________________________________
> Gdcm-developers mailing list
> Gdc...@li...
> https://lists.sourceforge.net/lists/listinfo/gdcm-developers
--
Mathieu
|