Reputation: 47
I want to display a DICOM image on android. Is there any way to convert a DICOM image to JPEG on android?
Currently the default conversion of DICOM to bitmap returns null
. Any idea how to proceed ?
Upvotes: 2
Views: 2263
Reputation: 122
Another option if you are using Java is looking into DCM4CHE. It's an open source library to read/write and manipulate DICOM files. Reading is as easy as this:
DicomInputStream din = new DicomInputStream(new File("your_image.dcm"));
DicomObject doj = din.readDicomObject();
The DicomObject
then contains all kinds of data. There's a neat documentation over here (https://dcm4che.atlassian.net/wiki/spaces/proj/overview?mode=global)
There are certainly easier options to be fair, but if reading and displaying the image is all you want, you might as well give it a shot.
Upvotes: 0
Reputation: 4750
Imebra provides Java bindings for android and the documentation shows how to extract an image ready to be displayed:
// Allocate a transforms chain: contains all the transforms to execute before displaying
// an image. Can be empty
TransformsChain transformsChain = new TransformsChain();
// Let's use a DrawBitmap object to generate a buffer with the pixel data. We will
// use that buffer to create an Android Bitmap
com.imebra.dicom.DrawBitmap drawBitmap = new com.imebra.dicom.DrawBitmap(image, transformsChain);
int temporaryBuffer[] = new int[1]; // Temporary buffer. Just used to get the needed buffer size
int bufferSize = drawBitmap.getBitmap(image.getSizeX(), image.getSizeY(), 0, 0, image.getSizeX(), image.getSizeY(), temporaryBuffer, 0);
int buffer[] = new int[bufferSize]; // Ideally you want to reuse this in subsequent calls to getBitmap()
// Now fill the buffer with the image data and create a bitmap from it
drawBitmap.getBitmap(image.getSizeX(), image.getSizeY(), 0, 0, image.getSizeX(), image.getSizeY(), buffer, bufferSize);
Bitmap renderBitmap = Bitmap.createBitmap(buffer, image.getSizeX(), image.getSizeY(), Bitmap.Config.ARGB_8888);
imageView.setImageBitmap(renderBitmap);
Upvotes: 2