This article provides you with the easiest way of converting DICOM images to JPG, PNG, BMP and GIF formats in C#.
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, etc. which are exchanged between multiple entities to share the patient’s medical information.
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 JPG, GIF, PNG, BMP or some other image format. Accordingly, 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:
- JPG
- GIF
- PNG
- BMP
C# DICOM to JPG, GIF, PNG, and BMP Converter - Free Download
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 JPG in C#
The following are the steps to convert DICOM to JPG 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 JPG (if it is not set, the default active page will be converted).
- Save the converted JPG image using DicomImage.Save(string, ImageOptionsBase) method.
The following code sample converts a page in DICOM to JPG in C#.
Input DICOM
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 an 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#.
C# DICOM to PNG Conversion
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#.
Export DICOM to BMP in C#
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#.
Conclusion
In this article, you have learned how to convert DICOM images to PNG, JPG, BMP, and GIF formats in C#. You can easily integrate the provided code samples into your applications and perform DICOM conversion.
C# DICOM to Image Converter - Learn More
Explore more about working with images using Aspose.Imaging for .NET API.
See also
Info: You may find Aspose Text to GIF web app interesting.