This article explains how to convert DICOM to PNG in Java. It includes all the necessary details to set up the IDE, a step-by-step list, and a sample code to transform the file format from DCM to PNG in Java. You will get information to render all or selected pages from the sources DICOM file and generate customized raster images.
Steps to Convert DCM to PNG in Java
- Add the Aspose.Imaging library to your project for converting DICOM files to PNG
- Load the Aspose.Imaging license using setLicense to activate full library features
- Load the DICOM file (input.DCM) using Image.load() and cast it to DicomImage
- Retrieve and display the total number of pages in the DICOM file using getPageCount()
- Create a PngOptions object to define the PNG export settings
- Loop through each page of the DICOM image using a for loop
- Save each page as a separate PNG file using save() with unique filenames like Page-0.png, Page-1.png, etc.
These steps summarize the process to transform the file format from DICOM to PNG in Java. Load the source DICOM file into the Image class object, typecast it to the DicomImage class object and parse through all the pages in the DCM file. Transform each page to a PNG image in a loop and save it on the disk with a unique name.
Code for DICOM to PNG Converter in Java
This code has demonstrated the process to transform DICOM to PNG. If you save the image directly as a PNG file, it will save the first page only. However, if you iterate through all the pages in the DICOM file, you can save each page as a separate PNG file and customize it by setting various properties in the PngOptions.
This article has taught us the process to convert a DICOM file to a PNG. To convert a CDR file to JPG, refer to the article Convert CDR to JPG in Java.