Exemplo n.º 1
0
        private void printDocument_0_PrintPage(object sender, PrintPageEventArgs e)
        {
            ContentAlignment topRight      = this.AllowPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;
            RectangleF       printableArea = e.PageSettings.PrintableArea;
            GraphicsUnit     pixel         = GraphicsUnit.Pixel;
            RectangleF       bounds        = this.image_0.GetBounds(ref pixel);

            if (this.AllowPrintRotate && !(((printableArea.Width <= printableArea.Height) || (bounds.Width >= bounds.Height)) ? ((printableArea.Width >= printableArea.Height) || (bounds.Width <= bounds.Height)) : false))
            {
                this.image_0.RotateFlip(RotateFlipType.Rotate90FlipNone);
                bounds = this.image_0.GetBounds(ref pixel);
                if (topRight.Equals(ContentAlignment.TopLeft))
                {
                    topRight = ContentAlignment.TopRight;
                }
            }
            RectangleF ef = new RectangleF(0f, 0f, bounds.Width, bounds.Height);

            if (this.AllowPrintEnlarge || this.AllowPrintShrink)
            {
                SizeF ef2 = Class25.smethod_0(bounds.Size, printableArea.Size, false);
                if (!((!this.AllowPrintShrink || (ef2.Width >= ef.Width)) ? (!this.AllowPrintEnlarge || (ef2.Width <= ef.Width)) : false))
                {
                    ef.Size = ef2;
                }
            }
            ef = Class25.smethod_1(ef, new RectangleF(0f, 0f, printableArea.Width, printableArea.Height), topRight);
            e.Graphics.DrawImage(this.image_0, ef, bounds, GraphicsUnit.Pixel);
        }
        void GetImageForPrint(object sender, PrintPageEventArgs e)
        {
            PrintOptionsDialog pod = new PrintOptionsDialog();

            pod.ShowDialog();

            ContentAlignment alignment = pod.AllowPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;

            RectangleF   pageRect  = e.PageSettings.PrintableArea;
            GraphicsUnit gu        = GraphicsUnit.Pixel;
            RectangleF   imageRect = image.GetBounds(ref gu);

            // rotate the image if it fits the page better
            if (pod.AllowPrintRotate)
            {
                if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) ||
                    (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height))
                {
                    image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    imageRect = image.GetBounds(ref gu);
                    if (alignment.Equals(ContentAlignment.TopLeft))
                    {
                        alignment = ContentAlignment.TopRight;
                    }
                }
            }
            RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);;

            // scale the image to fit the page better
            if (pod.AllowPrintEnlarge || pod.AllowPrintShrink)
            {
                SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false);
                if ((pod.AllowPrintShrink && resizedRect.Width < printRect.Width) ||
                    pod.AllowPrintEnlarge && resizedRect.Width > printRect.Width)
                {
                    printRect.Size = resizedRect;
                }
            }
            // align the image
            printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height), alignment);

            e.Graphics.DrawImage(image, printRect, imageRect, GraphicsUnit.Pixel);
        }
Exemplo n.º 3
0
        void DrawImageForPrint(object sender, PrintPageEventArgs e)
        {
            // Create the output settins
            SurfaceOutputSettings printOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false);

            ApplyEffects(printOutputSettings);

            Image image;
            bool  disposeImage = ImageOutput.CreateImageFromSurface(surface, printOutputSettings, out image);

            try {
                ContentAlignment alignment = conf.OutputPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;

                // prepare timestamp
                float  footerStringWidth  = 0;
                float  footerStringHeight = 0;
                string footerString       = null;           //DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
                if (conf.OutputPrintFooter)
                {
                    footerString = FilenameHelper.FillPattern(conf.OutputPrintFooterPattern, captureDetails, false);
                    using (Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) {
                        footerStringWidth  = e.Graphics.MeasureString(footerString, f).Width;
                        footerStringHeight = e.Graphics.MeasureString(footerString, f).Height;
                    }
                }

                // Get a rectangle representing the printable Area
                RectangleF pageRect = e.PageSettings.PrintableArea;
                if (e.PageSettings.Landscape)
                {
                    float origWidth = pageRect.Width;
                    pageRect.Width  = pageRect.Height;
                    pageRect.Height = origWidth;
                }

                // Subtract the dateString height from the available area, this way the area stays free
                pageRect.Height -= footerStringHeight;

                GraphicsUnit gu        = GraphicsUnit.Pixel;
                RectangleF   imageRect = image.GetBounds(ref gu);
                // rotate the image if it fits the page better
                if (conf.OutputPrintAllowRotate)
                {
                    if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) || (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height))
                    {
                        image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                        imageRect = image.GetBounds(ref gu);
                        if (alignment.Equals(ContentAlignment.TopLeft))
                        {
                            alignment = ContentAlignment.TopRight;
                        }
                    }
                }

                RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);
                // scale the image to fit the page better
                if (conf.OutputPrintAllowEnlarge || conf.OutputPrintAllowShrink)
                {
                    SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false);
                    if ((conf.OutputPrintAllowShrink && resizedRect.Width < printRect.Width) || conf.OutputPrintAllowEnlarge && resizedRect.Width > printRect.Width)
                    {
                        printRect.Size = resizedRect;
                    }
                }

                // align the image
                printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height), alignment);
                if (conf.OutputPrintFooter)
                {
                    //printRect = new RectangleF(0, 0, printRect.Width, printRect.Height - (dateStringHeight * 2));
                    using (Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) {
                        e.Graphics.DrawString(footerString, f, Brushes.Black, pageRect.Width / 2 - (footerStringWidth / 2), pageRect.Height);
                    }
                }
                e.Graphics.DrawImage(image, printRect, imageRect, GraphicsUnit.Pixel);
            } finally {
                if (disposeImage && image != null)
                {
                    image.Dispose();
                    image = null;
                }
            }
        }
        void DrawImageForPrint(object sender, PrintPageEventArgs e)
        {
            ContentAlignment alignment = conf.OutputPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;

            // prepare timestamp
            float  footerStringWidth  = 0;
            float  footerStringHeight = 0;
            string footerString       = null;       //DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();

            if (conf.OutputPrintFooter)
            {
                footerString = FilenameHelper.FillPattern(conf.OutputPrintFooterPattern, captureDetails, false);
                using (Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) {
                    footerStringWidth  = e.Graphics.MeasureString(footerString, f).Width;
                    footerStringHeight = e.Graphics.MeasureString(footerString, f).Height;
                }
            }

            // Get a rectangle representing the printable Area
            RectangleF pageRect = e.PageSettings.PrintableArea;

            // Subtract the dateString height from the available area, this way the area stays free
            pageRect.Height -= footerStringHeight;

            GraphicsUnit gu        = GraphicsUnit.Pixel;
            RectangleF   imageRect = image.GetBounds(ref gu);

            // rotate the image if it fits the page better
            if (conf.OutputPrintAllowRotate)
            {
                if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) || (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height))
                {
                    image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    imageRect = image.GetBounds(ref gu);
                    if (alignment.Equals(ContentAlignment.TopLeft))
                    {
                        alignment = ContentAlignment.TopRight;
                    }
                }
            }

            RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);

            // scale the image to fit the page better
            if (conf.OutputPrintAllowEnlarge || conf.OutputPrintAllowShrink)
            {
                SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false);
                if ((conf.OutputPrintAllowShrink && resizedRect.Width < printRect.Width) || conf.OutputPrintAllowEnlarge && resizedRect.Width > printRect.Width)
                {
                    printRect.Size = resizedRect;
                }
            }

            // align the image
            printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height), alignment);
            if (conf.OutputPrintFooter)
            {
                //printRect = new RectangleF(0, 0, printRect.Width, printRect.Height - (dateStringHeight * 2));
                using (Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) {
                    e.Graphics.DrawString(footerString, f, Brushes.Black, pageRect.Width / 2 - (footerStringWidth / 2), pageRect.Height);
                }
            }
            if (conf.OutputPrintInverted)
            {
                using (Bitmap negativeBitmap = ImageHelper.CreateNegative((Bitmap)image)) {
                    e.Graphics.DrawImage(negativeBitmap, printRect, imageRect, GraphicsUnit.Pixel);
                }
            }
            else
            {
                e.Graphics.DrawImage(image, printRect, imageRect, GraphicsUnit.Pixel);
            }
        }
Exemplo n.º 5
0
        void DrawImageForPrint(object sender, PrintPageEventArgs e)
        {
            PrintOptionsDialog pod = printOptionsDialog;

            ContentAlignment alignment = pod.AllowPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;

            if (conf.OutputPrintInverted)
            {
                // Invert Bitmap
                BitmapBuffer bb = new BitmapBuffer((Bitmap)image, false);
                bb.Lock();
                for (int y = 0; y < bb.Height; y++)
                {
                    for (int x = 0; x < bb.Width; x++)
                    {
                        Color color         = bb.GetColorAt(x, y);
                        Color invertedColor = Color.FromArgb(color.A, color.R ^ 255, color.G ^ 255, color.B ^ 255);
                        bb.SetColorAt(x, y, invertedColor);
                    }
                }
                bb.Dispose();
            }

            RectangleF   pageRect  = e.PageSettings.PrintableArea;
            GraphicsUnit gu        = GraphicsUnit.Pixel;
            RectangleF   imageRect = image.GetBounds(ref gu);

            // rotate the image if it fits the page better
            if (pod.AllowPrintRotate)
            {
                if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) ||
                    (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height))
                {
                    image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    imageRect = image.GetBounds(ref gu);
                    if (alignment.Equals(ContentAlignment.TopLeft))
                    {
                        alignment = ContentAlignment.TopRight;
                    }
                }
            }
            RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);;

            // scale the image to fit the page better
            if (pod.AllowPrintEnlarge || pod.AllowPrintShrink)
            {
                SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false);
                if ((pod.AllowPrintShrink && resizedRect.Width < printRect.Width) ||
                    pod.AllowPrintEnlarge && resizedRect.Width > printRect.Width)
                {
                    printRect.Size = resizedRect;
                }
            }

            // prepare timestamp
            float dateStringWidth  = 0;
            float dateStringHeight = 0;

            if (conf.OutputPrintTimestamp)
            {
                Font   f          = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular);
                string dateString = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
                dateStringWidth  = e.Graphics.MeasureString(dateString, f).Width;
                dateStringHeight = e.Graphics.MeasureString(dateString, f).Height;
                e.Graphics.DrawString(dateString, f, Brushes.Black, pageRect.Width / 2 - (dateStringWidth / 2), pageRect.Height - dateStringHeight);
            }

            // align the image
            printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height - dateStringHeight * 2), alignment);

            e.Graphics.DrawImage(image, printRect, imageRect, GraphicsUnit.Pixel);
        }
Exemplo n.º 6
0
        private void GetImageForPrint(object sender, PrintPageEventArgs e)
        {
            ContentAlignment alignment = this.AllowPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;

            RectangleF   pageRect  = e.PageSettings.PrintableArea;
            GraphicsUnit gu        = GraphicsUnit.Pixel;
            RectangleF   imageRect = image.GetBounds(ref gu);

            // rotate the image if it fits the page better
            if (this.AllowPrintRotate)
            {
                if (e.PageSettings.Landscape)
                {
                    if ((pageRect.Width < pageRect.Height && imageRect.Width < imageRect.Height) ||
                        (pageRect.Width > pageRect.Height && imageRect.Width > imageRect.Height))
                    {
                        if (!rotated)
                        {
                            image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                            rotated = true;
                        }
                        else
                        {
                            image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            rotated = false;
                        }
                        imageRect = image.GetBounds(ref gu);
                        if (alignment.Equals(ContentAlignment.TopLeft))
                        {
                            alignment = ContentAlignment.TopRight;
                        }
                    }
                }
                else
                {
                    if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) ||
                        (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height))
                    {
                        if (!rotated)
                        {
                            image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                            rotated = true;
                        }
                        else
                        {
                            image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            rotated = false;
                        }
                        imageRect = image.GetBounds(ref gu);
                        if (alignment.Equals(ContentAlignment.TopLeft))
                        {
                            alignment = ContentAlignment.TopRight;
                        }
                    }
                }
            }
            RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);;

            // scale the image to fit the page better
            if (this.AllowPrintEnlarge || this.AllowPrintShrink)
            {
                SizeF resizedRect = new SizeF();
                if (e.PageSettings.Landscape)
                {
                    SizeF size = new SizeF(pageRect.Size.Height, pageRect.Size.Width);
                    resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, size, Fill);
                }
                else
                {
                    resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, Fill);
                }

                if ((this.AllowPrintShrink && resizedRect.Width < printRect.Width) ||
                    this.AllowPrintEnlarge && resizedRect.Width > printRect.Width)
                {
                    printRect.Size = resizedRect;
                }
            }
            if (e.PageSettings.Landscape)
            {
                // align the image
                printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Height, pageRect.Width), alignment);
            }
            else
            {
                // align the image
                printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height), alignment);
            }
            e.Graphics.DrawImage(image, printRect, imageRect, GraphicsUnit.Pixel);
        }