Save images in C#

To FTP

To save a GdPicture image to an FTP server, use the SaveToFTP method of the GdPictureImaging class. It 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 image format:
    • 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.
  • Host — Name of the host server.
  • Path — Path to the image file on the FTP server.
  • Login — User’s login to authenticate on the server.
  • Password — User’s password.
  • FTPPort — FTP server’s port number.

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);