public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { magnificationFactor = GetFieldValueAsInt(FieldType.MAGNIFICATION_FACTOR); applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); bbbSrc = new BitmapBuffer(applyBitmap, applyRect); try { bbbSrc.Lock(); base.Apply(graphics, applyBitmap, applyRect, renderMode); } finally { bbbSrc.Dispose(); bbbSrc = null; } }
public virtual void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { applyRect = IntersectRectangle(applyBitmap.Size, rect); if (applyRect.Width == 0 || applyRect.Height == 0) { // nothing to do return; } bbb = new BitmapBuffer(applyBitmap, applyRect); try { bbb.Lock(); for(int y=0;y<bbb.Height; y++) { for(int x=0;x<bbb.Width; x++) { if(parent.Contains(applyRect.Left+x, applyRect.Top+y) ^ Invert) { IteratePixel(x, y); } } } } finally { bbb.DrawTo(graphics, applyRect.Location); bbb.Dispose(); bbb = null; } }
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); }