Load a DICOM image from local storage in C#

DICOM

To load a DICOM image from local storage, use the CreateGdPictureImageFromFile method of the GdPictureImaging class. This creates a new GdPicture representation of the image, and it returns the unique image identifier (imageID) of the newly created GdPicture image. This method accepts the following parameters:

  • FilePath — The path to the image file.
  • LoadInMemory — Optional: A Boolean value that specifies whether to load the file content into the local machine’s memory. It’s set to false by default.
  • DirectAccess — Optional: A Boolean value that specifies whether to load only the image properties, the metadata, and the thumbnail without loading the image itself. When set to false, the method loads the image itself.

If you load the same image to the GdPictureImaging object multiple times, use the GetLastPath method instead of the FilePath parameter. This method returns the file path of the latest loaded or saved file used by the GdPictureImaging object.

When you no longer need an image resource, release it with the ReleaseGdPictureImage method.

To load an image from local storage, use the following code:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load a DICOM image from the specified path.
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.dcm");
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
// Release the loaded GdPicture image.
gdpictureImaging.ReleaseGdPictureImage(imageID);