
DICOM is a standard file format for storing medical images. In medical examinations, radiology, cardiology, and other healthcare domains widely use DICOM files. If you are developing a medical imaging system or want to work with medical data, learning to create DICOM files programmatically is essential. In this post, you will learn how to create a DICOM file using C#. Let’s begin.
This article shall cover the following topics:
Aspose.Medical—DICOM File Generator
For creating DICOM files, we will use Aspose.Medical for .NET. It allows developers to create, edit, and process DICOM files programmatically within .NET applications.
Install Aspose.Medical for .NET.
Please download the SDK from the releases. You may also install it via the NuGet Package Manager using the following command:
Install-Package Aspose.Medical
Step-by-Step Guide to Create a DICOM File
Creating DICOM files programmatically is simple using Aspose.Medical for .NET. Follow these simple steps to generate a basic DICOM file in C#:
- Create an instance of the
DicomFile
class. - Add data to the newly created DICOM file using the
AddOrUpdate()
method. - Finally, call the
Save()
method to save the DCM file to a specified path.
Here’s a complete code snippet to create a basic DICOM file with some essential metadata.
How the Code Works
The DicomFile
class is the main class that represents a complete DICOM file. It includes all the metadata and image data required by the DICOM standard. The following line creates a new, empty DICOM file. You can then populate it with metadata and pixel data.
Aspose.Medical.Dicom.DicomFile dicomFile = new();
The Dataset
is a collection of DICOM elements. The DICOM elements store patient information, scan details, image data, and more in the form of tags. The Tag
class provides a list of standard DICOM tags. The code below adds or updates a DICOM element (in this case, the acquisition frame rate) using a predefined tag.
dicomFile.Dataset.AddOrUpdate(Tag.XAAcquisitionFrameRate, 17.95);
Once you’ve added the necessary data using predefined tags, use the Save()
method to write the file to disk. The following code segment saves the file in .dcm
format at the specified path.
dicomFile.Save("sample.dcm");
Get a Free License
You can get a free temporary license and explore the full functionality of Aspose.Medical for .NET without any limitations. It is fast, simple, and only takes a minute.
Create DICOM DCM Files: Free Resources
Explore more with these helpful links:
Conclusion
Creating a DICOM file programmatically is not complex anymore. Using Aspose.Medical for .NET, you can easily generate fully compliant DICOM files with just a few lines of code. Feel free to reuse this example by adding real pixel data or connecting it with imaging devices.
If you have questions or need any help working with DICOM files, please feel free to reach out on our support forum. The support team and community are always ready to assist.