Load an image from a byte array in C#
Image
To load an 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 theDocumentFormatenumeration 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 image from a byte array, use the following code:
using GdPictureImaging gdpictureImaging = new GdPictureImaging();// Create a byte array from an image.byte[] byteaArray = File.ReadAllBytes(@"C:\temp\source.jpg");// 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 image. Dim byteaArray = File.ReadAllBytes("C:\temp\source.jpg") ' 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