DICOM (Digital Imaging and Communications in Medicine) is a standard file format for storing medical imaging information. The information stored in the DICOM images is managed in the form of datasets including the header and the image data set. Most often, DICOM images contain medical scans such as ultrasounds, MRIs and etc. which are exchanged between multiple entities to share the patient’s medical information.
In order to view the DICOM images, various offline and online DICOM viewers are available in the market. However, if you want to embed DICOM images in presentations or webpages, you will have to convert them into JPEG, GIF, PNG, BMP or some other image format. In accordance with this scenario, in this article, you will learn how to convert DICOM images programmatically in C#. Ultimately, you will be able to convert DICOM to the following image formats:
C# DICOM Converter API
In order to convert DICOM images, we’ll use Aspose.Imaging for .NET which is an easy to use API for creating and manipulating various types of images within .NET applications. Aspose.Imaging for .NET is hosted on NuGet as well as available as downloadable binaries.
Convert DICOM to JPEG in C#
The following are the steps to convert DICOM to JPEG in C#:
- Load the DICOM file into a FileStream object.
- Create an object of DicomImage class and initialize it with the FileStream object.
- Select the active page in DICOM that you want to convert to JPEG (if it is not set, the default active page will be converted).
- Save the converted JPEG image using DicomImage.Save(string, ImageOptionsBase) method.
The following code sample converts a page in DICOM to JPEG in C#.
DICOM to JPEG
Convert DICOM to GIF in C#
Converting DICOM to GIF is as simple as pie. Just access the DICOM file and save it with .gif extension. The following are the steps to convert DICOM to animated GIF in C#:
- Access the DICOM file using DicomImage class.
- Save the converted GIF image using DicomImage.Save(string, ImageOptionsBase) method.
The following code sample shows how to convert DICOM to GIF in C#.
Convert DICOM to PNG in C#
Converting DICOM to PNG is as same as converting DICOM to JPEG. Simply access the DICOM file using DicomImage class and save it with .png extension. The following code sample shows how to convert a DICOM to PNG in C#.
Convert DICOM to BMP in C#
In order to convert DICOM to BMP, you can repeat the same steps to access the DICOM file using the DicomImage class. Once done, use DicomImage.Save(string, ImageBaseOptions) method to save DICOM as BMP. The following code sample shows how to convert DICOM to BMP in C#.
Learn more about Aspose.Imaging for .NET
Explore more about working with images using Aspose.Imaging for .NET API.