Search code examples
androidandroid-imagedicom

Android development: how to open a .dcm file as a bitmap?


I'm currently trying to make an android dicom app Following code opens pictures drom res/drawable in "ussual" image formats, but it doesn't work with .dcm

public class BitmapView extends View
{
    public BitmapView(Context context) {
            super(context);
    }
    @Override
    public void onDraw(Canvas canvas) {
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.test);
        canvas.drawColor(Color.BLACK);
        canvas.drawBitmap(bmp, 10, 10, null);
    }
}

in the main activity:

protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(new BitmapView(this));     
    }

thanks in advance!


Solution

  • Dicom is a kind of generic container. Inside a Dicom file you can find a huge variety of image formats. From grayscale ones to RGB, from single frame to multiframe ones, with pixel value ranges not in the ordinary 8 bit (24/32 in RGB/RGBA) but also in 12 or 16 bit grayscales.

    Dicom files include many elements (fields) indicating the type of the contents and even how such contents should be presented. It is not as simple as converting the Dicom image to BMP.

    If you are retrieving Dicom images from a PACS, I would suggest using WADO service. This way, you can obtain Jpeg images (the results of having applied a presentation state to the contents of the Dicom file).

    The other option is to use some utility to convert the Dicom file to a more conventional image format. There are some excellent open source tools, such as dcmj2pnm, from the DCMTK toolkit.