Load a bitmap (BMP) from a remote URL in C#
To load a bitmap image from a remote URL, use the CreateGdPictureImageFromHTTP
method from the GdPictureImaging
class. This method creates a new GdPicture representation of an image and returns a unique non-zero image identifier — imageID
— of the newly created GdPicture image. This method requires two different sets of parameters depending on the type of server:
Loading a bitmap image from a public server
When the server you want to get the image from is public, then the CreateGdPictureImageFromHTTP
method requires the following parameters:
Host
— Server host name where the image is located.Path
— Image file path on the host server.HTTPPort
— Server port number.
Remember to release the image resource once you stop using it. Use 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
.
To load a bitmap image from a public server, use the following code:
using GdPictureImaging gdpictureImaging = new GdPictureImaging();// Create a GdPicture image from a bitmap image on a public server.int imageID = gdpictureImaging.CreateGdPictureImageFromHTTP("https://pspdfkit.com", "downloads/load-a-file/source.bmp", 443);// Save to a PNG image.gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");gdpictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging() ' Create a GdPicture image from a bitmap image on a public server. Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromHTTP("https://pspdfkit.com", "downloads/load-a-file/source.bmp", 443) ' Save to a PNG image. gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png") gdpictureImaging.ReleaseGdPictureImage(imageID)End Using
Loading a bitmap image from a protected server
When the server you want to get the image from is private, then the CreateGdPictureImageFromHTTP
method requires the following parameters:
Uri
— Full path to a bitmap image.Login
— Login used to authenticate the connection on the server.Password
— Password required to authenticate the connection on the server.
Remember to release the image resource once you stop using it. Use 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
.
To load a bitmap image from a protected server, use the following code:
using GdPictureImaging gdpictureImaging = new GdPictureImaging();// Create a GdPicture image from a bitmap image on a protected server.int imageID = gdpictureImaging.CreateGdPictureImageFromHTTP("https://pspdfkit.com/downloads/load-a-file/source.bmp", "admin", "password");// Save to a PNG image.gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");gdpictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging() ' Create a GdPicture image from a bitmap image on a protected server. Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromHTTP("https://pspdfkit.com/downloads/load-a-file/source.bmp", "admin", "password") ' Save to a PNG image. gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png") gdpictureImaging.ReleaseGdPictureImage(imageID)End Using