The following example shows how to save images to files:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Extract images from documentIEnumerable<PageImageArea>images=parser.GetImages();// Check if images extraction is supportedif(images==null){Console.WriteLine("Page images extraction isn't supported");return;}// Iterate over imagesforeach(PageImageAreaimageinimages){// Open the image streamusing(StreamimageStream=image.GetImageStream()){// Create the file to save imageusing(StreamdestStream=File.Create(Guid.NewGuid().ToString()+image.FileType.Extension)){byte[]buffer=newbyte[4096];intreaded=0;do{// Read data from the image streamreaded=imageStream.Read(buffer,0,buffer.Length);if(readed>0){// Write data to the file streamdestStream.Write(buffer,0,readed);}}while(readed>0);}}}}
The following example shows how to save images to files in a different format:
// Create an instance of Parser classusing(Parserparser=newParser(filePath)){// Extract images from documentIEnumerable<PageImageArea>images=parser.GetImages();// Check if images extraction is supportedif(images==null){Console.WriteLine("Page images extraction isn't supported");return;}// Create the options to save images in PNG formatImageOptionsoptions=newImageOptions(ImageFormat.Png);// Iterate over imagesforeach(PageImageAreaimageinimages){// Open the image streamusing(StreamimageStream=image.GetImageStream(options)){// Create the file to save imageusing(StreamdestStream=File.Create(Guid.NewGuid().ToString()+".png")){byte[]buffer=newbyte[4096];intreaded=0;do{// Read data from the image streamreaded=imageStream.Read(buffer,0,buffer.Length);if(readed>0){// Write data to the file streamdestStream.Write(buffer,0,readed);}}while(readed>0);}}}}