Load an image for conversion from a stream in C#

Image

To load and convert an image from a stream object to a different file type, use the LoadFromStream method from the GdPictureDocumentConverter class. This method requires the following parameters:

  • Stream — The stream object of an image.
  • DocumentFormat — The file format represented as a member of the DocumentFormat enumeration.

To load and convert an image from a stream object, use the following code:

// Create a stream object from an image file.
using Stream streamFile = new FileStream(@"C:\temp\source.jpeg", FileMode.Open);
// Create a new `gdpictureDocumentConverter` object.
using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Specify the file format.
GdPicture14.DocumentFormat format = GdPicture14.DocumentFormat.DocumentFormatJP2;
// Load the stream object to the `gdpictureDocumentConverter` object.
gdpictureDocumentConverter.LoadFromStream(streamFile, format);
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");