Save images in C#

To Remote URL

To save a GdPicture image to a remote URL, use the SaveToHTTP method of the GdPictureImaging class. This method uses the HTTP PUT protocol to upload the image. It also uses the following parameters:

  • imageID — The ID of the GdPicture image.
  • ImageFormat — The image format represented as a member of the DocumentFormat enumeration.
  • EncoderParameter — The compression or encoding quality used. This parameter and its range depend on the type of image formats:
    • JPEG format — Image quality between 1 (lowest) and 100 (highest).
    • PNG format — Compression level between 0 (no compression and fastest encoding) and 9 (maximum compression and slowest encoding).
    • TIFF format — Compression scheme specified with the TiffCompression enumeration.
    • JPEG2000 format — Compression rate between 1 (highest quality) and 512 (lowest quality).
    • WebP format — Image quality between 1 (lowest) and 100 (highest).
    • For other formats, set this parameter to 0.
  • Address — The address of the remote URL.
  • Login — Optional: User’s login to authenticate on the server.
  • Password — Optional: User’s password.

When you no longer need an image resource, release it with the ReleaseGdPictureImage method.

When transferring data to or from remote servers, you can optionally use the SetHttpTransferBufferSize method to specify the maximum package size of the transferred data. By default, the buffer size is 4096.

The following example saves a previously loaded JPG image to a byte array:

using GdPictureImaging gdPictureImaging = new GdPictureImaging();
// Create a GdPicture image from a JPG file.
int imageID = gdPictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
// Set the package size to 2048.
gdpictureImaging.SetHttpTransferBufferSize(2048);
// Save the GdPicture image to the FTP server.
gdPictureImaging.SaveToFTP(imageID, GdPicture14.DocumentFormat.DocumentFormatJPEG,
75, "ftp.pspdfkit.com", "/demo/source.jpg", "user", "passw0rd", 21);
gdPictureImaging.ReleaseGdPictureImage(imageID);