Provides extra options for loading PowerPoint format files.
public class CodecsPowerPointOptions using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing.Core;// This example shows how to load only visible PowerPoint slidespublic void CodecsPowerPointOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "test.pptx");string dstFileName = Path.Combine(LEAD_VARS.ImagesDir, "Out.png");// Set CodecsPowerPointLoadOptions.ShowHiddenSlides to false to load only visible slidescodecs.Options.PowerPoint.Load.ShowHiddenSlides = false; // CodecsPowerPointOptions// Load the first visible slideusing (RasterImage image = codecs.Load(srcFileName, 1)){codecs.Save(image, dstFileName, RasterImageFormat.Png, 0);}// Clean upcodecs.Dispose();}/// <!--CodecsPowerPointOptions-->/// <!--CodecsPtokaOptions-->public void CodecsPtokaOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "BusinessForm.ica");// Setting new options.// CodecsPtokaOptions & CodecsPtokaLoadOptions referencecodecs.Options.Ptoka.Load.Resolution = 500;RasterImage image = codecs.Load(srcFileName);// Clean upimage.Dispose();codecs.Dispose();}/// <!--CodecsPtokaOptions-->/// <!--CodecsRawOptions-->private struct RawData{public int Width; // Width of imagepublic int Height; // Height of imagepublic int BitsPerPixel; // Bits per pixel of image--if palettized, a gray palette is generatedpublic RasterViewPerspective ViewPerspective; // View perspective of raw data (TopLeft, BottomLeft, etc)public RasterByteOrder Order; // Rgb or Bgrpublic int XResolution; // Horizontal resolution in DPIpublic int YResolution; // Vertical resolution in DPIpublic int Offset; // Offset into file where raw data beginspublic bool Padding; // true if each line of data is padded to four bytespublic bool ReverseBits; // true if the bits of each byte are reversed}private RawData myRawData;private void codecs_LoadInformation(object sender, CodecsLoadInformationEventArgs e){// Set the informatione.Format = RasterImageFormat.Raw;e.Width = myRawData.Width;e.Height = myRawData.Height;e.BitsPerPixel = myRawData.BitsPerPixel;e.XResolution = myRawData.XResolution;e.YResolution = myRawData.YResolution;e.Offset = myRawData.Offset;if (myRawData.Padding)e.Pad4 = true;e.Order = myRawData.Order;if (myRawData.ReverseBits)e.LeastSignificantBitFirst = true;e.ViewPerspective = myRawData.ViewPerspective;// If image is palettized create a grayscale paletteif (e.BitsPerPixel <= 8){int colors = 1 << e.BitsPerPixel;RasterColor[] palette = new RasterColor[colors];for (int i = 0; i < palette.Length; i++){byte val = (byte)((i * 255) / (colors - 1));palette[i] = new RasterColor(val, val, val);}e.SetPalette(palette);}}public void CodecsRawOptionsExample(){RasterCodecs codecs = new RasterCodecs();// First, load a JPEG or CMP fileRasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"));// Save this image as RAW data// Set RAW options// CodecsRawOptions & CodecsRawSaveOptions referencecodecs.Options.Raw.Save.Pad4 = true;codecs.Options.Raw.Save.ReverseBits = true;codecs.Options.Save.OptimizedPalette = true;string rawFileName = Path.Combine(LEAD_VARS.ImagesDir, "Test.raw");codecs.Save(image, rawFileName, RasterImageFormat.Raw, 0);// Save information about this image so we can use it to load the RAW filemyRawData = new RawData();myRawData.Width = image.Width;myRawData.Height = image.Height;myRawData.BitsPerPixel = image.BitsPerPixel;myRawData.ViewPerspective = image.ViewPerspective;myRawData.Order = image.Order;myRawData.XResolution = image.XResolution;myRawData.YResolution = image.YResolution;myRawData.Offset = 0;myRawData.Padding = true;myRawData.ReverseBits = true;// We dont need the image anymoreimage.Dispose();// Now load this RAW image back// First subscribe to the LoadInformation event so we can set the image informationcodecs.LoadInformation += new EventHandler<CodecsLoadInformationEventArgs>(codecs_LoadInformation);// Load the imageimage = codecs.Load(rawFileName);codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "raw.bmp"), RasterImageFormat.Bmp, image.BitsPerPixel);// Unsubscribe from the eventcodecs.LoadInformation -= new EventHandler<CodecsLoadInformationEventArgs>(codecs_LoadInformation);// Clean upimage.Dispose();codecs.Dispose();}/// <!--CodecsRawOptions-->/// <!--CodecsRtfOptions-->public void CodecsRtfOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "test.rtf");// Setting new options.codecs.Options.RasterizeDocument.Load.LeftMargin = 1.00;codecs.Options.RasterizeDocument.Load.TopMargin = 1.25;codecs.Options.RasterizeDocument.Load.PageWidth = 8.50;codecs.Options.RasterizeDocument.Load.PageHeight = 11.00;codecs.Options.RasterizeDocument.Load.BottomMargin = 1.00;codecs.Options.RasterizeDocument.Load.RightMargin = 1.25;codecs.Options.Rtf.Load.BackColor = RasterColor.White; // CodecsRtfOptions & CodecsRtfLoadOptions referenceRasterImage image = codecs.Load(srcFileName);codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "rtf.bmp"), RasterImageFormat.Bmp, image.BitsPerPixel);// Clean upimage.Dispose();codecs.Dispose();}/// <!--CodecsRtfOptions-->/// <!--CodecsTiffOptions-->public void CodecsTiffOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "OCR1.TIF");// Get all Information about the Tiff file that you want to load.CodecsImageInfo imageInfo = codecs.GetInformation(srcFileName, true);if (imageInfo.Tiff.IsImageFileDirectoryOffsetValid){codecs.Options.Tiff.Load.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset;codecs.Options.Tiff.Save.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset;}// CodecsTiffOptions & CodecsTiffLoadOptions referencecodecs.Options.Tiff.Load.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid;codecs.Options.Tiff.Save.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid;codecs.Options.Tiff.Load.IgnorePhotometricInterpretation = true;codecs.Options.Tiff.Load.IgnoreViewPerspective = false;codecs.Options.Tiff.Load.UseFastConversion = false;RasterImage image = codecs.Load(srcFileName);codecs.Options.Tiff.Save.NoPalette = imageInfo.Tiff.HasNoPalette;codecs.Options.Tiff.Save.PreservePalette = imageInfo.Tiff.HasNoPalette;// Set the tiffSave options// CodecsTiffSaveOptions referencecodecs.Options.Tiff.Save.NoPageNumber = false;codecs.Options.Tiff.Save.NoSubFileType = false;codecs.Options.Tiff.Save.UsePhotometricInterpretation = true;codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.YcbCr;codecs.Options.Tiff.Save.UseTileSize = true;codecs.Options.Tiff.Save.TileHeight = 200;codecs.Options.Tiff.Save.TileWidth = 200;codecs.Options.Tiff.Save.NoLzwAutoClear = false;codecs.Options.Tiff.Save.SavePlanar = false;codecs.Options.Tiff.Save.UsePredictor = false;// make the output file have the same format as the input, so Tiff->Tiff, BigTiff->BigTiffcodecs.Options.Tiff.Save.BigTiff = imageInfo.Tiff.IsBigTiff;//saving the imagecodecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "testtiff1.TIF"), RasterImageFormat.Tif, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);//change some tiffsave options.codecs.Options.Tiff.Save.NoPageNumber = true;codecs.Options.Tiff.Save.NoSubFileType = true;codecs.Options.Tiff.Save.UsePhotometricInterpretation = false;codecs.Options.Tiff.Save.UseTileSize = false;codecs.Options.Tiff.Save.NoPalette = false;codecs.Options.Tiff.Save.PreservePalette = true;codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.Palette;//save the image with different name.codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "testtiff2.TIF"), RasterImageFormat.CcittGroup4, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);// Clean upimage.Dispose();codecs.Dispose();}/// <!--CodecsTiffOptions-->/// <!--CodecsTxtOptions-->public void CodecsTxtOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "test.txt");// Setting new options.codecs.Options.RasterizeDocument.Load.LeftMargin = 1.00;codecs.Options.RasterizeDocument.Load.TopMargin = 1.25;codecs.Options.RasterizeDocument.Load.PageWidth = 8.50;codecs.Options.RasterizeDocument.Load.PageHeight = 11.00;codecs.Options.RasterizeDocument.Load.BottomMargin = 1.00;codecs.Options.RasterizeDocument.Load.RightMargin = 1.25;// CodecsTxtOptions & CodecsTxtLoadOptions referencecodecs.Options.Txt.Load.BackColor = RasterColor.White;codecs.Options.Txt.Load.FaceName = "Courier New";codecs.Options.Txt.Load.FontColor = new RasterColor(255, 0, 0);codecs.Options.Txt.Load.Highlight = RasterColor.White;codecs.Options.Txt.Load.FontSize = 12;codecs.Options.Txt.Load.Italic = false;codecs.Options.Txt.Load.Strikethrough = false;codecs.Options.Txt.Load.Underline = false;codecs.Options.Txt.Load.Bold = true;codecs.Options.Txt.Load.Enabled = true;codecs.Options.Txt.Load.TabSize = 3;RasterImage image = codecs.Load(srcFileName);codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "txt.bmp"), RasterImageFormat.Bmp, image.BitsPerPixel);// Clean upimage.Dispose();codecs.Dispose();}/// <!--CodecsTxtOptions-->/// <!--CodecsWmfOptions-->public void CodecsWmfOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");// Setting new options.// CodecsWmfOptions & CodecsWmfLoadOptions referencecodecs.Options.Wmf.Load.XResolution = 500;codecs.Options.Wmf.Load.YResolution = 500;codecs.Options.Wmf.Load.Resolution = 0;RasterImage image = codecs.Load(srcFileName);codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "WmfImage.wmf"), RasterImageFormat.Wmf, image.BitsPerPixel);image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "WmfImage.wmf"));codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "wmf.bmp"), RasterImageFormat.Bmp, image.BitsPerPixel);// Clean upimage.Dispose();codecs.Dispose();}/// <!--CodecsWmfOptions-->/// <!--CodecsXpsOptions-->public void CodecsXpsOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "test.xps");string pngDestFileName = Path.Combine(LEAD_VARS.ImagesDir, "PngCompressed.xps");string jpegDestFileName = Path.Combine(LEAD_VARS.ImagesDir, "JpegCompressed.xps");// Set the resolution for loading XPS files to 300 by 300 DPI (Dots per inch)// CodecsXpsOptions & CodecsXpsLoadOptions referencecodecs.Options.RasterizeDocument.Load.XResolution = 300;codecs.Options.RasterizeDocument.Load.YResolution = 300;// Load the source fileRasterImage image = codecs.Load(srcFileName);// Save this file as XPS with PNG compression and quality factor of 9 (highest compression)// CodecsXpsSaveOptions referencecodecs.Options.Xps.Save.PngQualityFactor = 9;codecs.Save(image, pngDestFileName, RasterImageFormat.Xps, 24);// Save this file as XPS with JPEG 422 compression and quality factor of 255 (highest compression)codecs.Options.Xps.Save.JpegQualityFactor = 255;codecs.Save(image, jpegDestFileName, RasterImageFormat.Xps, 24);// Clean upimage.Dispose();codecs.Dispose();}/// <!--CodecsXpsOptions-->/// <!--CodecsXlsOptions-->public void CodecsXlsOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "test.Xls");// Enable using the RasterizeDocumentOptionsCodecsRasterizeDocumentLoadOptions rasterizeDocumentLoadOptions = codecs.Options.RasterizeDocument.Load;// Fit the document at 8.5 by 11 inches at 96 DPI keeping the aspect ratiorasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit;rasterizeDocumentLoadOptions.PageWidth = 8.5;rasterizeDocumentLoadOptions.PageHeight = 11;rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch;rasterizeDocumentLoadOptions.XResolution = 300;rasterizeDocumentLoadOptions.YResolution = 300;// Load each sheet in a separate page// CodecsXlsOptions & CodecsXlsLoadOptions referencecodecs.Options.Xls.Load.MultiPageSheet = true;codecs.Options.Xls.Load.MultiPageEnableMargins = false;codecs.Options.Xls.Load.MultiPageUseSheetWidth = false;codecs.Options.Xls.Load.PageOrderDownThenOver = false;codecs.Options.Xls.Load.ShowHiddenSheet = false;// Load the source fileusing (RasterImage image = codecs.Load(srcFileName)){// Show the image informationDebug.WriteLine("Image has {0} pages", image.PageCount);Debug.WriteLine("Image size: {0} by {1} pixels at {2} by {3} DPI",image.ImageWidth, image.ImageHeight, image.XResolution, image.YResolution);}// Clean upcodecs.Dispose();}/// <!--CodecsXlsOptions-->/// <!--CodecsExcelOptions-->public void CodecsExcelOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "test.Xls");// Enable using the RasterizeDocumentOptionsCodecsRasterizeDocumentLoadOptions rasterizeDocumentLoadOptions = codecs.Options.RasterizeDocument.Load;// Fit the document at 8.5 by 11 inches at 96 DPI keeping the aspect ratiorasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit;rasterizeDocumentLoadOptions.PageWidth = 8.5;rasterizeDocumentLoadOptions.PageHeight = 11;rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch;rasterizeDocumentLoadOptions.XResolution = 300;rasterizeDocumentLoadOptions.YResolution = 300;// Load each sheet in a separate page - CodecsExcelOptions & CodecsExcelLoadOptions referencecodecs.Options.Excel.Load.MultiPageSheet = false;codecs.Options.Excel.Load.MultiPageEnableMargins = false;codecs.Options.Excel.Load.MultiPageUseSheetWidth = false;codecs.Options.Excel.Load.PageOrderDownThenOver = false;codecs.Options.Excel.Load.ShowHiddenSheets = false; // ShowHiddenSheet reference// Load the source fileusing (RasterImage image = codecs.Load(srcFileName)){// Show the image informationDebug.WriteLine("Image has {0} pages", image.PageCount);Debug.WriteLine("Image size: {0} by {1} pixels at {2} by {3} DPI",image.ImageWidth, image.ImageHeight, image.XResolution, image.YResolution);//To save as BMP, uncomment out this line://codecs.Save(image, srcFileName + ".bmp", RasterImageFormat.Bmp, 24);}// Clean upcodecs.Dispose();}/// <!--CodecsExcelOptions-->/// <!--CodecsRasterizeDocumentLoadOptions-->public void RasterizeDocumentExample(){// Initialize the RasterCodecs object to useRasterCodecs codecs = new RasterCodecs();// Enable using the RasterizeDocumentOptionsCodecsRasterizeDocumentLoadOptions rasterizeDocumentLoadOptions = codecs.Options.RasterizeDocument.Load;// No margins (only used with RTF and TXT files)rasterizeDocumentLoadOptions.LeftMargin = 0;rasterizeDocumentLoadOptions.TopMargin = 0;rasterizeDocumentLoadOptions.RightMargin = 0;rasterizeDocumentLoadOptions.BottomMargin = 0;// The PDF file we are testing. This could be an XPS, RTF, TXT or XLS file as wellstring imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf");// Show the file informationusing (CodecsImageInfo imageInfo = codecs.GetInformation(imageFileName, true)){CodecsDocumentImageInfo documentImageInfo = imageInfo.Document;// If this is a document file, show the document informationif (documentImageInfo.IsDocumentFile){Debug.WriteLine("Document file");Debug.WriteLine(" Original size is: {0} by {1} {2}",documentImageInfo.PageWidth, documentImageInfo.PageHeight, documentImageInfo.Unit);Debug.WriteLine(" Using current rasterization, load size will be: {0} by {1} pixels at {2} by {3}",imageInfo.Width, imageInfo.Height, imageInfo.XResolution, imageInfo.YResolution);}else{// Regular raster image, show the image informationDebug.WriteLine("Raster file");Debug.WriteLine(" Original size is: {0} by {1} pixels at {2} by {3}",imageInfo.Width, imageInfo.Height, imageInfo.XResolution, imageInfo.YResolution);}}// Example 1. Load at original document size at 300 DPIrasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.None;rasterizeDocumentLoadOptions.XResolution = 300;rasterizeDocumentLoadOptions.YResolution = 300;using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)){ShowResult(codecs, image);}// Example 2. Fit the document at 640 by 480 pixels at 96 DPI keeping the aspect ratiorasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit;rasterizeDocumentLoadOptions.PageWidth = 640;rasterizeDocumentLoadOptions.PageHeight = 480;rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Pixel;rasterizeDocumentLoadOptions.XResolution = 96;rasterizeDocumentLoadOptions.YResolution = 96;using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)){ShowResult(codecs, image);}// Example 3. Fit the document at 8.5 by 11 inches at 96 DPI keeping the aspect ratiorasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit;rasterizeDocumentLoadOptions.PageWidth = 8.5;rasterizeDocumentLoadOptions.PageHeight = 11;rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch;rasterizeDocumentLoadOptions.XResolution = 300;rasterizeDocumentLoadOptions.YResolution = 300;using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)){ShowResult(codecs, image);}// Example 4. Stretch the image to always be 4 by 4 inches at 150 DPI. Aspect ratio may differrasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Stretch;rasterizeDocumentLoadOptions.PageWidth = 4;rasterizeDocumentLoadOptions.PageHeight = 4;rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch;rasterizeDocumentLoadOptions.XResolution = 150;rasterizeDocumentLoadOptions.YResolution = 150;using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)){ShowResult(codecs, image);}codecs.Dispose();}private static void ShowResult(RasterCodecs codecs, RasterImage image){CodecsRasterizeDocumentLoadOptions rasterizeDocumentLoadOptions = codecs.Options.RasterizeDocument.Load;Debug.WriteLine("Showing result..");Debug.WriteLine(" Current rasterization options:");Debug.WriteLine(" Size mode is: {0}", rasterizeDocumentLoadOptions.SizeMode);Debug.WriteLine(" Page size is {0} by {1} {2}",rasterizeDocumentLoadOptions.PageWidth, rasterizeDocumentLoadOptions.PageHeight, rasterizeDocumentLoadOptions.Unit);Debug.WriteLine(" Resolution is {0} by {1}",rasterizeDocumentLoadOptions.XResolution, rasterizeDocumentLoadOptions.YResolution);Debug.WriteLine(" Loaded raster image size is: {0} by {1} at {2} by {3}",image.ImageWidth, image.ImageHeight, image.XResolution, image.YResolution);// Code to verify our results// Get the suggested page width and height in pixelsdouble pageWidthInPixels;double pageHeightInPixels;switch (rasterizeDocumentLoadOptions.Unit){case CodecsRasterizeDocumentUnit.Inch:pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth * rasterizeDocumentLoadOptions.XResolution;pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight * rasterizeDocumentLoadOptions.YResolution;break;case CodecsRasterizeDocumentUnit.Millimeter:pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth * rasterizeDocumentLoadOptions.XResolution * 25.400000025908000026426160026955;pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight * rasterizeDocumentLoadOptions.YResolution * 25.400000025908000026426160026955;break;case CodecsRasterizeDocumentUnit.Pixel:default:pageWidthInPixels = rasterizeDocumentLoadOptions.PageWidth;pageHeightInPixels = rasterizeDocumentLoadOptions.PageHeight;break;}// Verifyswitch (rasterizeDocumentLoadOptions.SizeMode){case CodecsRasterizeDocumentSizeMode.Fit:case CodecsRasterizeDocumentSizeMode.FitAlways:// The image width/height must not be greater than suggested page width/heightDebug.WriteLine("Image width/height must be less than or equal to page width/height");System.Diagnostics.Debug.Assert(image.ImageWidth <= pageWidthInPixels);System.Diagnostics.Debug.Assert(image.ImageHeight <= pageHeightInPixels);break;case CodecsRasterizeDocumentSizeMode.FitWidth:// The image width must be equal to the suggested page widthDebug.WriteLine("Image width must be equal to page width");System.Diagnostics.Debug.Assert(image.ImageWidth == pageWidthInPixels);break;case CodecsRasterizeDocumentSizeMode.Stretch:// The image width/height must be equal to the suggested page width/heightDebug.WriteLine("Image width/height must be equal to suggested page width/height");System.Diagnostics.Debug.Assert(image.ImageWidth == pageWidthInPixels);System.Diagnostics.Debug.Assert(image.ImageHeight == pageHeightInPixels);break;case CodecsRasterizeDocumentSizeMode.None:default:Debug.WriteLine("Loading at original document page size");// No checkingbreak;}}/// <!--CodecsRasterizeDocumentLoadOptions-->/// <!--CodecsDocLoadOptions-->public void CodecsDocLoadOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "test.doc");// Enable using the RasterizeDocumentOptionsCodecsRasterizeDocumentLoadOptions rasterizeDocumentLoadOptions = codecs.Options.RasterizeDocument.Load;// Fit the document at 8.5 by 11 inches at 96 DPI keeping the aspect ratiorasterizeDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit;rasterizeDocumentLoadOptions.PageWidth = 8.5;rasterizeDocumentLoadOptions.PageHeight = 11;rasterizeDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch;rasterizeDocumentLoadOptions.XResolution = 300;rasterizeDocumentLoadOptions.YResolution = 300;// Load each page at 1-bits/pixelcodecs.Options.Doc.Load.BitsPerPixel = 1; // CodecsDocLoadOptions & CodecsDocOptions references// Load the source fileusing (RasterImage image = codecs.Load(srcFileName)){// Show the image informationDebug.WriteLine("Image has {0} pages", image.PageCount);Debug.WriteLine("Image size: {0} by {1} pixels at {2} by {3} DPI",image.ImageWidth, image.ImageHeight, image.XResolution, image.YResolution);}// Clean upcodecs.Dispose();}/// <!--CodecsDocLoadOptions-->/// <!--CodecsAnzLoadOptions-->public void CodecsAnzLoadOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.Anz");string dstFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_AnzCoronal.bmp");// Set the load options to use// "view is from front" ANZ viewing optionscodecs.Options.Anz.Load.View = CodecsAnzView.Coronal; // CodecsAnzOptions & CodecsAnzLoadOptions reference// Load the source fileusing (RasterImage image = codecs.Load(srcFileName)){// Save the image as BMPcodecs.Save(image, dstFileName, RasterImageFormat.Bmp, 24);}// Clean upcodecs.Dispose();}/// <!--CodecsAnzLoadOptions-->/// <!--CodecsVffLoadOptions-->public void CodecsVffLoadOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.vff");string dstFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Vff_UpToDown.bmp");string dstFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Vff_LeftToRight.bmp");// Set the load options to use up to down along the X-Axis// CodecsVffOptions & CodecsVffLoadOptions referencecodecs.Options.Vff.Load.View = CodecsVffView.UpToDown;// Load the source fileusing (RasterImage image = codecs.Load(srcFileName)){// Save the image as BMPcodecs.Save(image, dstFileName1, RasterImageFormat.Bmp, 24);}// Now, set the load options to use left to right along the Y-Axiscodecs.Options.Vff.Load.View = CodecsVffView.LeftToRight;// Re-load the source fileusing (RasterImage image = codecs.Load(srcFileName)){// Save the image as BMPcodecs.Save(image, dstFileName2, RasterImageFormat.Bmp, 24);}// Clean upcodecs.Dispose();}/// <!--CodecsVffLoadOptions-->/// <!--CodecsRtfOptions.LoadMetafile-->[DllImport("Gdi32")]private static extern int DeleteEnhMetaFile(IntPtr hemf);public void LoadRtfAsMetafileExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.rtf");// Load the source file as a metafileIntPtr hemf = codecs.Options.Rtf.LoadMetafile(srcFileName, 1);if (hemf != IntPtr.Zero){// Use the metafile here// Finally, delete it using the Windows APIDeleteEnhMetaFile(hemf);}// Clean upcodecs.Dispose();}/// <!--CodecsRtfOptions.LoadMetafile-->/// <!--CodecsSaveOptions.RetrieveDataFromImage-->private int myMode;public void RetrieveDataFromImageExample(){using (RasterCodecs codecs = new RasterCodecs()){string srcFile = Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp");string blankFile = Path.Combine(LEAD_VARS.ImagesDir, "Sample1_Blank.bmp");string defaultFile = Path.Combine(LEAD_VARS.ImagesDir, "Sample1_Default.bmp");string invertedFile = Path.Combine(LEAD_VARS.ImagesDir, "Sample1_Inverted.bmp");// Load the source imageusing (RasterImage image = codecs.Load(srcFile)){// Subscribe to the SaveImage eventcodecs.SaveImage += new EventHandler<CodecsSaveImageEventArgs>(codecs_SaveImage);// First, set RetrieveDataFromImage to false and save// This should generate a blank imagemyMode = 0;codecs.Options.Save.RetrieveDataFromImage = false;codecs.Save(image, blankFile, RasterImageFormat.Bmp, 24);// Next, set RetrieveDataFromImage to true but do not// change the data, this should generate the correct image and is the equivalant// to calling Save without subscribing to SaveImagemyMode = 1;codecs.Options.Save.RetrieveDataFromImage = true;codecs.Save(image, defaultFile, RasterImageFormat.Bmp, 24);// Finally, leave RetrieveDataFromImage as true but change the data by inverting// the scanlines, this should generate an inverted imagemyMode = 2;codecs.Save(image, invertedFile, RasterImageFormat.Bmp, 24);codecs.SaveImage -= new EventHandler<CodecsSaveImageEventArgs>(codecs_SaveImage);}}}private void codecs_SaveImage(object sender, CodecsSaveImageEventArgs e){// This example works with 24 bpp images onlyDebug.Assert(e.Image.BitsPerPixel == 24);switch (myMode){case 0:// Do not do anythingbreak;case 1:// Do not do anythingbreak;case 2:// Invert the image data{int scanlineLength = e.Image.BytesPerLine;byte[] scanline = new byte[scanlineLength];// Loop through all the scanlines in the datafor (int y = 0; y < e.Lines; y++){// Get this rowe.Buffer.GetData(y * scanlineLength, scanline, 0, scanlineLength);// Process it by inverting every pixel datafor (int x = 0; x < scanlineLength; x++){scanline[x] = (byte)(255 - scanline[x]);}// Copy it back to the event buffere.Buffer.SetData(y * scanlineLength, scanline, 0, scanlineLength);}}break;}}/// <!--CodecsSaveOptions.RetrieveDataFromImage-->/// <!--CodecsVectorLoadOptions-->public void CodecsVectorLoadOptionsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "random.dxf");//Check if it is a vector fileCodecsImageInfo info = codecs.GetInformation(srcFileName, false);Debug.WriteLine($"Is {srcFileName} a vector file? : {info.Vector.IsVectorFile}");Debug.WriteLine($"Units: {info.Vector.Unit}");//Parallelogram dataCodecsVectorImageInfo codecsVectorImageInfo = info.Vector;Debug.WriteLine($"Parallelogram Max X: {codecsVectorImageInfo.ParallelogramMaxX}");Debug.WriteLine($"Parallelogram Max Y: {codecsVectorImageInfo.ParallelogramMaxY}");Debug.WriteLine($"Parallelogram Max Z: {codecsVectorImageInfo.ParallelogramMaxZ}");Debug.WriteLine($"Parallelogram Min X: {codecsVectorImageInfo.ParallelogramMinX}");Debug.WriteLine($"Parallelogram Min Y: {codecsVectorImageInfo.ParallelogramMinY}");Debug.WriteLine($"Parallelogram Min Z: {codecsVectorImageInfo.ParallelogramMinZ}");// Set the vector load options// CodecsVectorOptions & CodecsVectorLoadOptions referencecodecs.Options.Vector.Load.BackgroundColor = new RasterColor(255, 255, 255);codecs.Options.Vector.Load.BitsPerPixel = 24;codecs.Options.Vector.Load.ForceBackgroundColor = true;codecs.Options.Vector.Load.ViewWidth = 800;codecs.Options.Vector.Load.ViewHeight = 800;codecs.Options.Vector.Load.ViewMode = CodecsVectorViewMode.UseBest;// Load the imageRasterImage image = codecs.Load(srcFileName);// do something with the image here// Clean upimage.Dispose();codecs.Dispose();}/// <!--CodecsVectorLoadOptions-->/// <!--CodecsPstOptions-->public void CodecsPstOptionsExample(){using (RasterCodecs codecs = new RasterCodecs()){string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "file.pst");int messageCount = 0;// Get number of messages in the PST filesusing (CodecsImageInfo imageInfo = codecs.GetInformation(srcFileName, true)){messageCount = imageInfo.Pst.MessageCount;}// Load all messages as pure textfor (int messageNumber = 1; messageNumber <= messageCount; messageNumber++){// Load message number 10 as text only// CodecsPstOptions & CodecsPstLoadOptions referencecodecs.Options.Pst.Load.MessageNumber = messageNumber;codecs.Options.Pst.Load.PlainText = true;// Load the imageusing (RasterImage image = codecs.Load(srcFileName)){// do something with the image here}}}}/// <!--CodecsPstOptions-->/// <!--RasterImageTypeConverter-->public void RasterImageTypeConverterExample(){string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif");// Construct the source URL to use the source file and load the imageUri uri = new Uri(srcFileName);RasterCodecs codecs = new RasterCodecs();// Create a new instance of the RasterImageTypeConverter classRasterImageTypeConverter rasterImageConverter = new RasterImageTypeConverter(codecs);// We should be able to convert from a URLDebug.Assert(rasterImageConverter.CanConvertFrom(uri.GetType()));// Convert the image// The return value from RasterImageTypeConverter.ConvertFrom might be an image that is// still loading. So, we must subscribe to the RasterCodecs.LoadAsyncCompleteted// event to obtain the finished imagecodecs.LoadAsyncCompleted += new EventHandler<CodecsLoadAsyncCompletedEventArgs>(rasterImageTypeConverterExample_LoadAsyncCompleted);object rasterImageObject = rasterImageConverter.ConvertFrom(uri);// Notice that the returned rasterImageObject is a RasterImage with IsLoading set to true at this point// The IsLoading will be false (and hence, the object will be usable) when the LoadAsyncCompleteted// fires.}private void rasterImageTypeConverterExample_LoadAsyncCompleted(object sender, CodecsLoadAsyncCompletedEventArgs e){// Check if the user canceled or if we have errorsif (e.Cancelled){Debug.WriteLine("Canceled by the user");}else if (e.Error != null){Debug.WriteLine("Error: " + e.Error.Message);}else{// Everything is OK, get the imageRasterImage image = e.Image;Debug.WriteLine("Image at {0} loaded OK, size: {1} by {2}", e.Uri, image.Width, image.Height);image.Dispose();}// Unsubscribe to the event and dispose the RasterCodecs objectRasterCodecs codecs = sender as RasterCodecs;codecs.LoadAsyncCompleted -= new EventHandler<CodecsLoadAsyncCompletedEventArgs>(rasterImageTypeConverterExample_LoadAsyncCompleted);codecs.Dispose();}/// <!--RasterImageTypeConverter-->/// <!--CodecsHtmlOptions-->public void CodecsHtmlOptions_Example(){using (RasterCodecs codecs = new RasterCodecs()){// Use the default HTML rendering engine - CodecsHtmlOptions & CodecsHtmlLoadOptions referencecodecs.Options.Html.Load.HtmlEngine = CodecsHtmlEngine.Auto;// Set the HTML options to only allow loading resources from the leadtools.com domain:codecs.Options.Html.Load.DomainWhitelist = "leadtools.com";// Disable all JavaScript embedded in the HTML filecodecs.Options.Html.Load.EnableJS = false;// Load the imageusing (RasterImage image = codecs.Load("file.html", 1)){// Do something with image}}}/// <!--CodecsHtmlOptions-->/// <!--CodecsCsvOptions-->public void CodecsCsvOptions_Example(){string csvFileName = Path.Combine(LEAD_VARS.ImagesDir, "sample.csv");string pngFileName = Path.Combine(LEAD_VARS.ImagesDir, "sample-csv.png");using (RasterCodecs codecs = new RasterCodecs()){// Change some CSV optionsCodecsCsvLoadOptions csvOptions = codecs.Options.Csv.Load; // CodecsCsvOptions referencecsvOptions.HeaderFontItalic = true;csvOptions.BodyFontName = "Arial";csvOptions.TableBorderColor = RasterColor.FromKnownColor(RasterKnownColor.Red);// Load the first page from a CSV fileusing (RasterImage image = codecs.Load(csvFileName, 1)){// Save it as PNGcodecs.Save(image, pngFileName, RasterImageFormat.Png, 0);}}}/// <!--CodecsCsvOptions-->/// <!--CodecsPdfLoadOptions.EnhanceThinLines-->public void CodecsEnhanceThinLinesOption_Example(){/* The following example shows you how to disable the thin line enhancement property */RasterCodecs codecs = new RasterCodecs();codecs.Options.Pdf.Load.EnhanceThinLines = false;string inputFile = @"MyFile.PDF";RasterImage rawImage = codecs.Load(inputFile, 24, CodecsLoadByteOrder.RgbOrGray, 1, -1);}/// <!--CodecsPdfLoadOptions.EnhanceThinLines-->/// <!--CodecsTxtLoadOptions.DefaultEncoding-->// This C# example shows you how to load a file called "Ansi.txt" that contains ANSI text.public void CodecsTxtLoadOptionsDefaultEncoding_Example(){using (RasterCodecs codecs = new RasterCodecs()){string srcFile = @"Ansi.txt";using (CodecsImageInfo info = codecs.GetInformation(srcFile, false)){if (!info.HasBom)codecs.Options.Txt.Load.DefaultEncoding = CodecsTxtEncoding.Ansi; /* Load as Ansi. Here you can bring up a message box asking the user to select the encoding */codecs.Options.Load.AllPages = true;using (RasterImage image = codecs.Load(srcFile)){codecs.Save(image, srcFile + ".tif", RasterImageFormat.TifLzw, 0);}}}}/// <!--CodecsTxtLoadOptions.DefaultEncoding-->/// <!--CodecsLoadOptions.Decrypt-->public void CodecsLoadOptionsDecrypt_Example(){/* This sample loads Encrypted.docx, which is encrypted with the password 'MyPassword' */using (RasterCodecs codecs = new RasterCodecs()){string srcFile = @"Encrypted.docx";codecs.Options.Load.Decrypt.Password = "MyPassword";codecs.Options.Load.AllPages = true;using (RasterImage image = codecs.Load(srcFile)){codecs.Save(image, srcFile + ".tif", RasterImageFormat.TifLzw, 0);}}}/// <!--CodecsLoadOptions.Decrypt-->///<!--CodecsHeicOptions-->public void CodecsHeicOptions_Example(){RasterCodecs codecs = new RasterCodecs();string fileName = "C:\temp\test.heic";using (RasterImage image = codecs.Load(fileName)){/* Save a HEIC file using qFactor of 30 and no stamp */string outFile30 = @"C:\temp\out30-NoStamp.heic";codecs.Options.Heic.Load.Multithreaded = false; // CodecsHeicLoadOptions referencecodecs.Options.Heic.Save.QualityFactor = 30; // CodecsHeicOptions & CodecsHeicSaveOptions referencecodecs.Save(image, outFile30, RasterImageFormat.Heic, 0);/* Save a HEIC file using qFactor of 40 and a stamp */string outFile40 = @"C:\temp\out40-Stamp.heic";codecs.Options.Heic.Save.QualityFactor = 40;codecs.Options.Heic.Save.SaveWithStamp = true;codecs.Options.Heic.Save.StampWidth = 320;codecs.Options.Heic.Save.StampHeight = codecs.Options.Heic.Save.StampWidth * image.Height / image.Width;codecs.Options.Heic.Save.StampBitsPerPixel = 24;codecs.Save(image, outFile40, RasterImageFormat.Heic, 0);}// Clean upcodecs.Dispose();}///<!--CodecsHeicOptions-->///<!--CodecsPowerPointOptions-->public static void CodecsPowerPointOptions_Example(){RasterCodecs codecs = new RasterCodecs();string filename = @"C:\temp\test.ppt";string savefilename = @"C:\temp\test-save.ppt";/* Specify PowerPointLoadOptions */CodecsPowerPointLoadOptions loadOptions = codecs.Options.PowerPoint.Load;loadOptions.ShowHiddenSlides = false;/* Load and Save PowerPoint */using (RasterImage image = codecs.Load(filename, 1)){codecs.Save(image, savefilename, RasterImageFormat.Ppt, 24);}// Clean upcodecs.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";}