public PdfImage ( PdfDocument Document, bool[,] BWImage, PdfImageControl ImageControl = null ) : this(Document) { // image dimensions WidthPix = BWImage.GetUpperBound(0) + 1; HeightPix = BWImage.GetUpperBound(1) + 1; // image represented as two dimension boolean array this.BWImage = BWImage; // default image control if (ImageControl != null) { CropRect = ImageControl.CropRect; CropPercent = ImageControl.CropPercent; ReverseBW = ImageControl.ReverseBW; GrayToBWCutoff = ImageControl.GrayToBWCutoff; Resolution = ImageControl.Resolution; ImageQuality = ImageControl.ImageQuality; SaveAs = ImageControl.SaveAs; } SaveAs = SaveImageAs.BWImage; // write image stream to pdf file WriteObjectToPdfFile(); return; }
private void ConstructorHelper ( Image Image, PdfImageControl ImageControl ) { // image control if (ImageControl == null) { ImageControl = new PdfImageControl(); } CropRect = ImageControl.CropRect; CropPercent = ImageControl.CropPercent; ReverseBW = ImageControl.ReverseBW; GrayToBWCutoff = ImageControl.GrayToBWCutoff; Resolution = ImageControl.Resolution; ImageQuality = ImageControl.ImageQuality; SaveAs = ImageControl.SaveAs; // image rectangle ImageRectangle(Image); // image size in pixels ImageSizeInPixels(Image); // convert the image to bitmap ConvertImageToBitmap(Image); // write to output file WriteObjectToPdfFile(); // exit return; }
//////////////////////////////////////////////////////////////////// // Constructor helper method //////////////////////////////////////////////////////////////////// private void ConstructorHelper ( Image Image, PdfImageControl ImageControl ) { // image control if (ImageControl == null) { ImageControl = new PdfImageControl(); } this.ImageControl = ImageControl; // image rectangle ImageRectangle(Image); // image size in pixels ImageSizeInPixels(Image); // convert the image to bitmap ConvertImageToBitmap(Image); // write to output file WriteObjectToPdfFile(); // exit return; }
/// <summary> /// Black and white image /// </summary> /// <param name="Document">PDF document (parent object)</param> /// <param name="BWImage">Black and white image</param> /// <param name="ImageControl">Image control (optional)</param> public PdfImage ( PdfDocument Document, Boolean[,] BWImage, PdfImageControl ImageControl = null ) : this(Document) { // image dimensions WidthPix = BWImage.GetUpperBound(0) + 1; HeightPix = BWImage.GetUpperBound(1) + 1; // image represented as two dimension boolean array this.BWImage = BWImage; // default image control if (ImageControl == null) { ImageControl = new PdfImageControl(); } ImageControl.SaveAs = SaveImageAs.BWImage; this.ImageControl = ImageControl; // write image stream to pdf file WriteObjectToPdfFile(); return; }
//////////////////////////////////////////////////////////////////// /// <summary> /// Constructor for image object /// </summary> /// <param name="Document">PDF document (parent object)</param> /// <param name="Image">Image bitmap or metafile</param> /// <param name="ImageControl">Image control (optional)</param> /// <remarks> /// <para> /// Image quality is a parameter that used by the .net framework /// during the compression of the image from bitmap to jpeg. If the parameter /// is missing or set to -1 the library saves the bitmap image as /// </para> /// <code> /// Bitmap.Save(MemoryStream, ImageFormat.Jpeg); /// </code> /// <para>If the ImageQuality parameter is 0 to 100, the library saves the bitmap image as</para> /// <code> /// EncoderParameters EncoderParameters = new EncoderParameters(1); /// EncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, ImageQuality); /// Bitmap.Save(MemoryStream, GetEncoderInfo("image/jpeg"), EncoderParameters); /// </code> /// <para> /// Microsoft does not specify the image quality factor used in the /// first method of saving. However, experimantaion and Internet comments shows that it is 75. /// </para> /// </remarks> //////////////////////////////////////////////////////////////////// public PdfImage ( PdfDocument Document, Image Image, PdfImageControl ImageControl = null ) : this(Document) { ConstructorHelper(Image, ImageControl); }
//////////////////////////////////////////////////////////////////// /// <summary> /// Constructor for image file /// </summary> /// <param name="Document">PDF document (parent object)</param> /// <param name="ImageFileName">Image file name</param> /// <param name="ImageControl">Image control</param> /// <remarks> /// <para> /// Image quality is a parameter that used by the .net framework /// during the compression of the image from bitmap to jpeg. If the parameter /// is missing or set to -1 the library saves the bitmap image as /// </para> /// <code> /// Bitmap.Save(MemoryStream, ImageFormat.Jpeg); /// </code> /// <para>If the ImageQuality parameter is 0 to 100, the library saves the bitmap image as</para> /// <code> /// EncoderParameters EncoderParameters = new EncoderParameters(1); /// EncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, ImageQuality); /// Bitmap.Save(MemoryStream, GetEncoderInfo("image/jpeg"), EncoderParameters); /// </code> /// <para> /// Microsoft does not specify the image quality factor used in the /// first method of saving. However, experimantaion and Internet comments shows that it is 75. /// </para> /// </remarks> //////////////////////////////////////////////////////////////////// public PdfImage ( PdfDocument Document, string ImageFileName, PdfImageControl ImageControl = null ) : this(Document) { ConstructorHelper(LoadImageFromFile(ImageFileName), ImageControl); }
//////////////////////////////////////////////////////////////////// /// <summary> /// PDF print document constructor /// </summary> /// <param name="Document">Current PDF document</param> /// <param name="ImageControl">Image control</param> //////////////////////////////////////////////////////////////////// public PdfPrintDocument ( PdfDocument Document, PdfImageControl ImageControl ) { // save document this.Document = Document; // save image control if (ImageControl == null) { ImageControl = new PdfImageControl(); } this.ImageControl = ImageControl; // set default resolution to 96 pixels per inch if (ImageControl.Resolution == 0) { ImageControl.Resolution = 96.0; } // make sure image control crop rectangles are empty this.ImageControl.CropRect = Rectangle.Empty; this.ImageControl.CropPercent = RectangleF.Empty; // create print document and preview controller objects PrintController = new PreviewPrintController(); // copy document's page size to default settings // convert page size from points to 100th of inch // do not set lanscape flag var PSize = new PaperSize { Width = (int)(Document.PageSize.Width / 0.72 + 0.5), Height = (int)(Document.PageSize.Height / 0.72 + 0.5) }; DefaultPageSettings.PaperSize = PSize; // assume document is in color DefaultPageSettings.Color = true; }
//////////////////////////////////////////////////////////////////// // Write object to PDF file //////////////////////////////////////////////////////////////////// internal void ConstructorHelper ( String DataString, String[] SegDataString, ErrorCorrection ErrorCorrection, Int32 QuietZone = 4 ) { // create QR Code object QREncoder Encoder = new QREncoder(); if (DataString != null) { Encoder.EncodeQRCode(DataString, ErrorCorrection, QuietZone); } else { Encoder.EncodeQRCode(SegDataString, ErrorCorrection, QuietZone); } // output matrix // NOTE: Black=true, White=flase BWImage = Encoder.OutputMatrix; // image width and height in pixels MatrixDimension = Encoder.MatrixDimension; WidthPix = MatrixDimension + 2 * QuietZone; HeightPix = WidthPix; // image control for QR code ImageControl = new PdfImageControl(); ImageControl.ReverseBW = true; ImageControl.SaveAs = SaveImageAs.BWImage; // write stream object WriteObjectToPdfFile(); return; }
//////////////////////////////////////////////////////////////////// /// <summary> /// PDF chart constructor /// </summary> /// <param name="Document">Document object parent of this chart.</param> /// <param name="Chart">.NET Chart object.</param> /// <param name="ImageControl">Chart display image control</param> /// <remarks> /// It is the responsibility of the calling program to release /// the resources of the input chart object. After PdfChart /// is commited to the PDF file /// </remarks> /// <example> /// <code> /// // create chart /// Chart MyChart = new Chart(); /// // build chart /// // ... /// // ... /// PdfImageControl ImageControl = new PdfImageControl(); /// ImageControl.SaveAs = SaveImageAs.IndexedImage; /// PdfChart MyPdfChart = new PdfChart(Document, MyChart, ImageControl); /// MyPdfChart.CommitToPdfFile(); /// MyChart.Dispose(); /// </code> /// </example> //////////////////////////////////////////////////////////////////// public PdfChart ( PdfDocument Document, Chart Chart, PdfImageControl ImageControl = null ) : base(Document) { // image control if (ImageControl == null) { ImageControl = new PdfImageControl(); } this.ImageControl = ImageControl; // save chart this.Chart = Chart; WidthPix = Chart.Width; HeightPix = Chart.Height; // save resolution if (ImageControl.Resolution != 0) // chart resolution in pixels per inch { this.Chart.RenderingDpiY = ImageControl.Resolution; } else { ImageControl.Resolution = this.Chart.RenderingDpiY; } // calculate chart size in user coordinates Width = WidthPix * 72.0 / (ImageControl.Resolution * Document.ScaleFactor); Height = HeightPix * 72.0 / (ImageControl.Resolution * Document.ScaleFactor); // exit }