read dicom file in csharp

To read a DICOM file in C# you can use a DICOM library like fo-dicom or ClearCanvas.ImageViewer. Here is an example of how to read and display a DICOM file using fo-dicom:

main.cs
using System;
using Dicom;
using Dicom.Imaging;
using Dicom.Imaging.Render;
using Dicom.IO.Buffer;
using System.Windows.Forms;

public void ReadDicomFile(string filePath)
{
    DicomFile dicomFile = DicomFile.Open(filePath);

    DicomPixelData pixelData = DicomPixelData.Create(dicomFile.Dataset);

    IPixelData image = PixelDataFactory.Create(pixelData, 0);

    // display the image in a picture box
    PictureBox pictureBox = new PictureBox();
    pictureBox.Image = new DicomImage(image).RenderImage().AsClonedBitmap();
    pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;

    // add the picture box to a form to display the image
    Form form = new Form();
    form.Controls.Add(pictureBox);
    form.ShowDialog();
}
730 chars
26 lines

This code reads a DICOM file at the provided filePath, converts its pixel data to an IPixelData object, and then uses the DicomImage class in fo-dicom to render the image as a bitmap which is displayed in a PictureBox. You can modify this example according to your needs.

gistlibby LogSnag