Load images from local storage in C#
Image
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 tofalse
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 tofalse
, 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 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