Load a vector image (SVG) from a byte array in C#
SVG
To load an SVG image from a byte array, use the CreateGdPictureImageFromByteArray
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:
Data
— The image data stored in a byte array.ImageFormat
— Optional: A member of theDocumentFormat
enumeration that specifies the image format.
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 SVG image from a byte array, use the following code:
using GdPictureImaging gdpictureImaging = new GdPictureImaging();// Create a byte array from an SVG image.byte[] byteaArray = File.ReadAllBytes(@"C:\temp\source.svg");// Create a GdPicture image from the byte array.int imageID = gdpictureImaging.CreateGdPictureImageFromByteArray(byteaArray);gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");gdpictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging() ' Create a byte array from an SVG image. Dim byteaArray = File.ReadAllBytes("C:\temp\source.svg") ' Create a GdPicture image from the byte array. Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromByteArray(byteaArray) gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png") gdpictureImaging.ReleaseGdPictureImage(imageID)End Using