Load a vector image (SVG) from local storage in C#
An SVG image is an XML-based vector image format. This means that you can load it in two different ways:
- To load the SVG as a raster image and lose the vectoring functionality, use the
CreateGdPictureImageFromFilemethod. - To preserve the vectoring functionality, load the SVG with the
CreateGdPictureImageFromMetaFilemethod.
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 tofalseby 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 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 UsingLoading 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.
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