PageImageAreaGetImageStream Method (ImageOptions)
Returns the image stream in a different format.

Namespace: GroupDocs.Parser.Data
Assembly: GroupDocs.Parser (in GroupDocs.Parser.dll) Version: 20.8.0
Syntax
public Stream GetImageStream(
	ImageOptions options
)

Parameters

options
Type: GroupDocs.Parser.OptionsImageOptions
The options which are used to extract the image.

Return Value

Type: Stream
A stream with the image.
Examples

The following example shows how to save images to files in a different format:

C#
// Create an instance of Parser class
using (Parser parser = new Parser(filePath))
{
    // Extract images from document
    IEnumerable<PageImageArea> images = parser.GetImages();

    // Check if images extraction is supported
    if (images == null)
    {
        Console.WriteLine("Page images extraction isn't supported");
        return;
    }

    // Create the options to save images in PNG format
    ImageOptions options = new ImageOptions(ImageFormat.Png);

    // Iterate over images
    foreach (PageImageArea image in images)
    {
        // Open the image stream
        using (Stream imageStream = image.GetImageStream(options))
        {
            // Create the file to save image
            using (Stream destStream = File.Create(Guid.NewGuid().ToString() + ".png"))
            {
                byte[] buffer = new byte[4096];
                int readed = 0;

                do
                {
                    // Read data from the image stream
                    readed = imageStream.Read(buffer, 0, buffer.Length);

                    if (readed > 0)
                    {
                        // Write data to the file stream
                        destStream.Write(buffer, 0, readed);
                    }
                }
                while (readed > 0);
            }
        }
    }
}
See Also