Convert DICOM to JPEG, GIF, PNG, BMP and PDF in Java

Convert DICOM to Image Java

Digital Imaging and Communications in Medicine (DICOM) is the standard for the communication and management of medical imaging information and related data. But you need a dedicated software to view a DICOM file and you cannot simply embed them in presentations or webpages. To tackle this limitation, you can convert a DICOM file to raster image formats such as JPEG, GIF, PNG, and BMP. In this article, you will learn how to convert a DICOM file programmatically in Java.

Java DICOM Converter API

Aspose.Imaging for Java is a powerful image creation and manipulation API that lets you convert DICOM file to JPEG, GIF, PNG, BMP and PDF with high fidelity. You can either download the API’s JAR or install it within your Maven-based applications using the following configurations.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-imaging</artifactId>
    <version>20.10</version>
    <classifier>jdk16</classifier>
</dependency>

DICOM to JPEG in Java

The following are the steps to convert DICOM to JPEG in Java:

The following code sample converts a page in DICOM to JPEG in Java.

Input DICOM

Input DICOM file

DICOM to JPEG

DICOM to JPG Converted

DICOM to GIF in Java

The steps to convert DICOM to GIF are same as we used above to convert DICOM to JPEG. Just access the DICOM file and save it with .gif extension. The following are the steps to convert DICOM to animated GIF in Java:

The following code sample shows how to convert DICOM to GIF in Java.

DICOM to GIF

Convert DICOM to GIF Java

DICOM to PNG in Java

As you may have guessed already, the steps to convert DICOM to PNG are same as used above to perform other conversions. Simply access the DICOM file using DicomImage class and save it with .png extension. If it is required to convert each page in a DICOM file to PNG, simply call DicomImage.getDicomPages() function to get DicomPage[] array and iterate over it as shown below.

The following code example shows how to convert a DICOM to PNG in Java.

DICOM to BMP in Java

Converting DICOM to BMP is as simple as pie. Access the DICOM file using the DicomImage class and use DicomImage.save(String filePath, ImageOptionsBase options) method to save DICOM as BMP. The following code sample shows how to convert DICOM to BMP in Java.

DICOM to PDF in Java

PDF is one of the most popular file formats. So, it is important to know how to transform a DICOM file to PDF in Java. The following code sample explains how to make this conversion.

Conclusion

In this article, you have learned how to convert DICOM file to JPEG, GIF, PNG, BMP and PDF in Java. You have also seen how to set an active page and convert all pages of a DICOM file. Please check the documentation to learn more about Aspose.Imaging API.

See also