private void Form1_Paint(object sender, PaintEventArgs e) { if (_lmvMyCallback != null && _lmvMyCallback.Image != null) { LeadRect destRect = LeadRect.Create(0, 0, this.ClientSize.Width, this.ClientSize.Height); using (RasterImage destImage = new RasterImage(RasterMemoryFlags.Conventional, this.ClientSize.Width, this.ClientSize.Height, _lmvMyCallback.Image.BitsPerPixel, _lmvMyCallback.Image.Order, _lmvMyCallback.Image.ViewPerspective, _lmvMyCallback.Image.GetPalette(), IntPtr.Zero, 0)) { // Resize the source image into the destination image ResizeCommand command = new ResizeCommand(); command.DestinationImage = destImage; command.Flags = RasterSizeFlags.Bicubic; command.Run(_lmvMyCallback.Image); destRect = RasterImage.CalculatePaintModeRectangle(destImage.ImageWidth, destImage.ImageHeight, destRect, RasterPaintSizeMode.FitAlways, RasterPaintAlignMode.Center, RasterPaintAlignMode.Center); LeadRect destClipRect = LeadRect.Create(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height); using (RasterGraphics rg = RasterImagePainter.CreateGraphics(destImage)) { rg.Graphics.DrawRectangle(new Pen(Color.Red), _lmvMyCallback.GuideRect.X, _lmvMyCallback.GuideRect.Y, _lmvMyCallback.GuideRect.Width, _lmvMyCallback.GuideRect.Height); } RasterImagePainter.Paint(destImage, e.Graphics, LeadRect.Empty, LeadRect.Empty, destRect, destClipRect, RasterPaintProperties.Default); } } }
private static RasterImage CreateTextFooter(LeadSize size, string tag) { var bpp = 24; var byteOrder = RasterByteOrder.Bgr; var viewPerspective = RasterViewPerspective.TopLeft; var image = new RasterImage(RasterMemoryFlags.Conventional, size.Width, size.Height, bpp, byteOrder, viewPerspective, null, null, 0); var fill = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.White)); fill.Run(image); using (var graphics = RasterImagePainter.CreateGraphics(image)) { using (var brush = new SolidBrush(Color.Black)) { using (var font = new Font(FontFamily.GenericSansSerif, size.Width / 128)) { var pos = new PointF(0, 0); { SizeF stringSize = new SizeF(); stringSize = graphics.Graphics.MeasureString(tag, font); float scaleX = (float)size.Width / stringSize.Width; float scaleY = (float)size.Height / stringSize.Height; scaleX = Math.Min(1f, scaleX); scaleY = Math.Min(1f, scaleY); graphics.Graphics.ScaleTransform(scaleX, scaleY); if (size.Height > (int)stringSize.Height) { size.Height = (int)stringSize.Height; } } graphics.Graphics.DrawString(tag, font, Brushes.Black, new PointF(0, 0)); } } } if (size.Height < image.Height) { var crop = new CropCommand(LeadRect.FromLTRB(0, 0, size.Width, size.Height)); crop.Run(image); } return(image); }