Save images in C#
Overview
To save a GdPicture image to a file, use one of the methods of the GdPictureImaging
class starting with SaveAs
. For example, the SaveAsPNG
method saves a GdPicture image to a PNG file. Refer to the list of supported file types to learn which file formats are available when saving an image to a file.
All saving methods use the following parameters:
imageID
— The ID of the GdPicture image.FilePath
— The file path where you want to save the image. If the specified file already exists, the method overwrites it.- A set of format-specific parameters — Parameters specific to the file format in which you want to save the image. In most cases, these parameters are optional.
When you no longer need an image resource, release it with the ReleaseGdPictureImage
method.
The following example saves a previously loaded JPG image to PNG format:
using GdPictureImaging gdPictureImaging = new GdPictureImaging();// Create a GdPicture image from a JPG file.int imageID = gdPictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");// Save the GdPicture image as a PNG file.gdPictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");gdPictureImaging.ReleaseGdPictureImage(imageID);
Using gdPictureImaging As GdPictureImaging = New GdPictureImaging() ' Create a GdPicture image from a JPG file. Dim imageID As Integer = gdPictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg") ' Save the GdPicture image as a PNG file. gdPictureImaging.SaveAsPNG(imageID, "C:\temp\output.png") gdPictureImaging.ReleaseGdPictureImage(imageID)End Using