This article provides a straightforward approach to convert 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, including datasets that contain both header and image data. DICOM images typically include medical scans such as ultrasounds and MRIs, which are shared among various entities to disseminate patient medical information.
While there are numerous offline and online DICOM viewers, embedding DICOM images in presentations or web pages often requires conversion to more common formats like JPG, GIF, PNG, or BMP. In this article, you’ll learn how to programmatically convert DICOM images in C#. By the end, you’ll be capable of converting DICOM images to the following formats:
- JPG
- GIF
- PNG
- BMP
C# DICOM to JPG, GIF, PNG, and BMP Converter - Free Download
To convert DICOM images, we will utilize Aspose.Imaging for .NET, a user-friendly API designed for creating and manipulating various types of images within .NET applications. You can find Aspose.Imaging for .NET on NuGet and also download the binaries.
Convert DICOM to JPG in C#
Follow these steps to convert DICOM to JPG in C#:
- Load the DICOM file into a FileStream object.
- Create an instance of the DicomImage class and initialize it with the FileStream object.
- Select the active page in the DICOM file for conversion to JPG (if not set, the default active page will be used).
- Save the converted JPG image using the DicomImage.Save(string, ImageOptionsBase) method.
Here’s a code sample that demonstrates how to convert a DICOM page to JPG in C#:
Input DICOM
DICOM to JPEG
Convert DICOM to GIF in C#
Converting DICOM to GIF is straightforward. Simply access the DICOM file and save it with the .gif extension. Here are the steps:
- Access the DICOM file using the DicomImage class.
- Save the converted GIF image using the DicomImage.Save(string, ImageOptionsBase) method.
Here’s a code sample for converting DICOM to GIF in C#:
C# DICOM to PNG Conversion
The process for converting DICOM to PNG is similar to that of converting to JPEG. Simply access the DICOM file using the DicomImage class and save it with the .png extension. Here’s a code sample for converting DICOM to PNG in C#:
Export DICOM to BMP in C#
To convert DICOM to BMP, follow the same steps as before to access the DICOM file using the DicomImage class. Once done, use the DicomImage.Save(string, ImageBaseOptions) method to save the DICOM as BMP. Here’s a code sample for this conversion:
Conclusion
In this article, you have learned how to convert DICOM images to PNG, JPG, BMP, and GIF formats using C#. You can easily integrate the provided code samples into your applications to perform DICOM conversions efficiently.
C# DICOM to Image Converter - Learn More
Explore more about working with images using the Aspose.Imaging for .NET API.
See also
Info: You may find the Aspose Text to GIF web app interesting.