Load a DICOM Image from Local Storage in C#

To load an 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.

Warning

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 an image from the specified path.
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
// Release the loaded GdPicture image.
gdpictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Load an image from the specified path.
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    ' Release the loaded GdPicture image.
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using

To load an image from image data stored in the System.Drawing.Bitmap object, use the CreateGdPictureImageFromBitmap 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 requires the System.Drawing.Bitmap object as its parameter.

Warning

When you no longer need an image resource and the System.Drawing.Bitmap object, release them with the ReleaseGdPictureImage and Dispose methods.

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

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load a bitmap image to a bitmap object.
Bitmap bitmapObject = new Bitmap(@"C:\temp\source.bmp");
// Load a GdPicture image from the bitmap object.
int imageID = gdpictureImaging.CreateGdPictureImageFromBitmap(bitmapObject);
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
// Release the loaded GdPicture image.
gdpictureImaging.ReleaseGdPictureImage(imageID);
// Release the bitmap object.
bitmapObject.Dispose();
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Load a bitmap image to a bitmap object.
    Dim bitmapObject As Bitmap = New Bitmap("C:\temp\source.bmp")
    ' Load a GdPicture image from the bitmap object.
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromBitmap(bitmapObject)
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    ' Release the loaded GdPicture image.
    gdpictureImaging.ReleaseGdPictureImage(imageID)
    ' Release the bitmap object.
    bitmapObject.Dispose()
End Using

An SVG image is an XML-based vector image format. This means that you can load it in two different ways:

Loading an SVG without the Vectoring Functionality

To load an SVG image from local storage without the vectoring functionality, 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.

Warning

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

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

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load an SVG image.
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.svg");
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
// Release the loaded GdPicture image.
gdpictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Load an SVG image.
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.svg")
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    ' Release the loaded GdPicture image.
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using

Loading an SVG Image with the Vectoring Functionality

To load an SVG image from local storage with the vectoring functionality, use the CreateGdPictureImageFromMetaFile 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.

  • ScaleBy — Optional: Multiplies the image by the specified factor.

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.

Warning

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

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

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load an SVG image.
int imageID = gdpictureImaging.CreateGdPictureImageFromMetaFile(@"C:\temp\source.svg", 5);
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
// Release the loaded GdPicture image.
gdpictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Load an SVG image.
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromMetaFile("C:\temp\source.svg", 5)
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    ' Release the loaded GdPicture image.
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using

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.

Warning

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);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Load a DICOM image from the specified path.
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.dcm")
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    ' Release the loaded GdPicture image.
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using

To load a TIFF image from local storage, use the TiffCreateMultiPageFromFile method of the GdPictureImaging class. This creates a new GdPicture representation of an image, and it returns the unique image identifier (imageID) of the newly created GdPicture image. The GdPicture image supports the multipage functionality. 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.

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.

Warning

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

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

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load a TIFF image from the specified path.
int imageID = gdpictureImaging.TiffCreateMultiPageFromFile(@"C:\temp\source.tif");
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
// Release the loaded GdPicture image.
gdpictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Load a TIFF image from the specified path.
    Dim imageID As Integer = gdpictureImaging.TiffCreateMultiPageFromFile("C:\temp\source.tif")
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    ' Release the loaded GdPicture image.
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using

Creating an Empty Image

To create an empty GdPicture image, use the CreateNewGdPictureImage 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:

  • Width— The image width in pixels.

  • Height — The image height in pixels.

  • Color depth represented by one of the following forms:

    • BitDepth — The number of bits used to indicate the color of a single pixel.

    • PixelFormat — A member of the PixelFormat enumeration that specifies the format color of the color data for each pixel in an image.

  • The background color specified by one of the following options:

Warning

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

To create a new 200×200 GdPicture image with a gray background, use the following code:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Create a new GdPicture image.
int imageID = gdpictureImaging.CreateNewGdPictureImage(200, 200,
        BitDepth: 32, gdpictureImaging.ARGB(100, 100, 100, 100));
// Save the GdPicture image to a file.
gdpictureImaging.SaveAsJPEG(imageID, @"C:\temp\output.jpg");
gdpictureImaging.Dispose();
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Create a new GdPicture image.
    Dim imageID As Integer = gdpictureImaging.CreateNewGdPictureImage(200, 200, BitDepth:=32, gdpictureImaging.ARGB(100, 100, 100, 100))
    ' Save the GdPicture image to a file.
    gdpictureImaging.SaveAsJPEG(imageID, "C:\temp\output.jpg")
    gdpictureImaging.Dispose()
End Using

Loading an Image from an FTP Server

To load an image from an FTP server, use the CreateGdPictureImageFromFTP 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:

  • Host — The name of the host server.

  • Path — The path to the image file on the FTP server.

  • Login — The user’s login to authenticate on the server.

  • Password — The user’s password.

  • FTPPort — The FTP server’s port number.

Warning

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

Information

When transferring data to or from remote servers, you can optionally use the SetHttpTransferBufferSize method to specify the maximum package size of the transferred data. By default, the buffer size is 4096.

To load an image from an FTP server, use the following code:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load an image from an FTP server.
int imageID = gdpictureImaging.CreateGdPictureImageFromFTP("ftp.pspdfkit.com",
    "/demo/source.jpg", "user", "passw0rd", 21);
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
// Release the loaded GdPicture image.
gdpictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Load an image from an FTP server.
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFTP("ftp.pspdfkit.com",
        "/demo/source.jpg", "user", "passw0rd", 21)
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    ' Release the loaded GdPicture image.
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using

Loading an Image from the Clipboard

To load an image from the clipboard, use the CreateGdPictureImageFromClipboard 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 doesn’t require any parameters.

Warning

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

To load an image from an area saved to the clipboard, use the following code:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Create a GdPicture image from the source image.
int imageSourceID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
// Copy a 100-by-100-pixel region of the source image to clipboard.
gdpictureImaging.CopyRegionToClipboard(imageSourceID, 0, 0, 100, 100);
// Create a new GdPicture image from the copied region.
int imageID = gdpictureImaging.CreateGdPictureImageFromClipboard();
gdpictureImaging.SaveAsJPEG(imageID, @"C:\temp\output.jpg");
// Release the loaded GdPicture image.
gdpictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Create a GdPicture image from the source image.
    Dim imageSourceID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
    ' Copy a 100-by-100-pixel region of the source image to clipboard.
    gdpictureImaging.CopyRegionToClipboard(imageSourceID, 0, 0, 100, 100)
    ' Create a new GdPicture image from the copied region.
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromClipboard()
    gdpictureImaging.SaveAsJPEG(imageID, "C:\temp\output.jpg")
    ' Release the loaded GdPicture image.
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using

Loading an Image from a Metafile

To load an image from a metafile, use the CreateGdPictureImageFromMetaFile 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.

  • ScaleBy — Optional: Multiplies the image by the specified factor.

The supported formats are the following:

  • EMF

  • WMF

  • SVG

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.

Warning

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

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

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load an image.
int imageID = gdpictureImaging.CreateGdPictureImageFromMetaFile(@"C:\temp\source.emf", 5);
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
// Release the loaded GdPicture image.
gdpictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Load an image.
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromMetaFile("C:\temp\source.emf", 5)
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    ' Release the loaded GdPicture image.
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using