Save images in C#
To save a GdPicture image to an FTP server, use the SaveToFTP method of the GdPictureImaging class.
Main parameters:
imageID— The GdPicture image identifier.ImageFormat— Output format as a member of theDocumentFormatenumeration.EncoderParameter— Encoding/compression parameter (depends on format).Host— FTP host name.
In some cross-platform GdPicture.API (net8.0) environments, the Host parameter for SaveToFTP(...) may need to be provided as a full FTP URI (for example, ftp://example.com) rather than a bare host name (example.com). If you get an error like “The URI prefix is not recognized.”, retry with the ftp:// prefix.
Path— Destination path on the FTP server.Login/Password— FTP credentials.FTPPort— FTP port (usually21).
SaveToFTP returns a GdPictureStatus, which should be checked.
Typical EncoderParameter values:
- JPEG — Quality
1to100 - PNG — Compression level
0to9 - TIFF — Values from
TiffCompressionenumeration - JPEG2000 — Compression rate
1to512 - WebP — Quality
1to100 - Other formats — Usually
0
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 an FTP server:
using GdPicture14;using System;
using GdPictureImaging gdPictureImaging = new GdPictureImaging();
int imageID = gdPictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");if (imageID == 0){ Console.WriteLine($"CreateGdPictureImageFromFile failed: {gdPictureImaging.GetStat()}"); return;}
gdPictureImaging.SetHttpTransferBufferSize(2048);
GdPictureStatus status = gdPictureImaging.SaveToFTP( imageID, DocumentFormat.DocumentFormatJPEG, 75, "ftp.pspdfkit.com", "/demo/source.jpg", "user", "passw0rd", 21);
if (status != GdPictureStatus.OK){ Console.WriteLine($"SaveToFTP failed: {status}");}
gdPictureImaging.ReleaseGdPictureImage(imageID);Imports GdPicture14
Using gdPictureImaging As New GdPictureImaging() Dim imageID As Integer = gdPictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg") If imageID = 0 Then Console.WriteLine($"CreateGdPictureImageFromFile failed: {gdPictureImaging.GetStat()}") Return End If
gdPictureImaging.SetHttpTransferBufferSize(2048)
Dim status As GdPictureStatus = gdPictureImaging.SaveToFTP( imageID, DocumentFormat.DocumentFormatJPEG, 75, "ftp.pspdfkit.com", "/demo/source.jpg", "user", "passw0rd", 21)
If status <> GdPictureStatus.OK Then Console.WriteLine($"SaveToFTP failed: {status}") End If
gdPictureImaging.ReleaseGdPictureImage(imageID)End Using