Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        private void _codecs_LoadImage(object sender, CodecsLoadImageEventArgs e)
        {
            if (_paintWhileLoadOption == PaintWhileLoadOption.PartialImage)
            {
                // One method is to use the Partial Image that is provided during this event to update
                // the RasterImageViewer control
                if ((e.Flags & CodecsLoadImageFlags.FirstRow) == CodecsLoadImageFlags.FirstRow)
                {
                    if (e.ImagePage == 1)
                    {
                        _viewer.Image = e.Image;
                        _viewer.Image.DisableEvents();
                    }
                }

                if (e.ImagePage == 1)
                {
                    Application.DoEvents();
                    Rectangle rc = new Rectangle(0, e.Row, _viewer.Image.Width, e.Lines);
                    _viewer.Invalidate(rc);
                }

                if ((e.Flags & CodecsLoadImageFlags.LastRow) == CodecsLoadImageFlags.LastRow && e.Page == e.LastPage)
                {
                    _viewer.Image.EnableEvents();
                }
            }
            // A second method, is to use PaintBuffer, and paint the data buffer that this event provides
            else
            {
                Application.DoEvents();
                Graphics g      = _viewer.CreateGraphics();
                LeadRect rcDest = new LeadRect(0, 0, e.Image.Width, e.Image.Height);
                RasterPaintProperties paintProps = _viewer.PaintProperties;
                if ((e.Flags & CodecsLoadImageFlags.Compressed) == CodecsLoadImageFlags.Compressed)
                {
                    RasterImagePainter.PaintBuffer(e.Image, g, LeadRect.Empty, LeadRect.Empty, rcDest, LeadRect.Empty, e.Buffer.Data, e.Row, -e.Lines, paintProps);
                }
                else
                {
                    RasterImagePainter.PaintBuffer(e.Image, g, LeadRect.Empty, LeadRect.Empty, rcDest, LeadRect.Empty, e.Buffer.Data, e.Row, e.Lines, paintProps);
                }

                g.Dispose();
            }

            if (_cancelLoad)
            {
                if (_viewer.Image != null)
                {
                    _viewer.Image = null;
                }
                e.Cancel = true;
            }

            // simulate a slow load
            Thread.Sleep(25);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                Rectangle dstRect = DestinationRectangle;

                RasterImagePainter.Paint(
                    _image,
                    e.Graphics,
                    Converters.ConvertRect(SourceRectangle),
                    LeadRect.Empty,
                    Converters.ConvertRect(dstRect),
                    Converters.ConvertRect(e.ClipRectangle),
                    _paintProperties);
            }
            catch
            {
            }
        }
Exemplo n.º 5
0
        // Draw on the viewer control and the image
        private void Draw(Point point, bool useHighlighter)
        {
            if (!_drawing)
            {
                return;
            }

            IntPtr pen     = useHighlighter ? _highlightWin32Pen : _redWin32Pen;
            int    mixMode = useHighlighter ? 9 : 13;

            Point point1 = TranslatePoint(_imageViewer, _imageViewer.Image, _oldPoint);
            Point point2 = TranslatePoint(_imageViewer, _imageViewer.Image, point);

            imageHDC = RasterImagePainter.CreateLeadDC(_imageViewer.Image);
            SetROP2(imageHDC, mixMode);
            DeleteObject(SelectObject(imageHDC, pen));
            MoveToEx(imageHDC, point1.X, point1.Y, IntPtr.Zero);
            LineTo(imageHDC, point2.X, point2.Y);
            RasterImagePainter.DeleteLeadDC(imageHDC);
        }
Exemplo n.º 6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                LeadRect dstRect = Leadtools.Demos.Converters.ConvertRect(DestinationRectangle);

#if LEADTOOLS_V17_OR_LATER
                RasterImagePainter.Paint(_image, e.Graphics,
#else
                _image.Paint(e.Graphics,
#endif // #if LEADTOOLS_V17_OR_LATER
                                         Leadtools.Demos.Converters.ConvertRect(SourceRectangle),
                                         LeadRect.Empty,
                                         dstRect,
                                         Leadtools.Demos.Converters.ConvertRect(e.ClipRectangle),
                                         RasterPaintProperties.Default);
            }
            catch
            {
            }
        }
Exemplo n.º 7
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (_sampleSymbologiesRasterImage == null)
            {
                return;
            }

            if (e.Index == -1)
            {
                return;
            }

            Rectangle rc = new Rectangle(e.Bounds.X + _delta, e.Bounds.Y + _delta, e.Bounds.Width - 10, e.Bounds.Height - _delta);

            if (_stringFormat == null)
            {
                _stringFormat               = new StringFormat();
                _stringFormat.Alignment     = StringAlignment.Center;
                _stringFormat.LineAlignment = StringAlignment.Far;
            }

            BarcodeSymbology symbology = (BarcodeSymbology)Items[e.Index];
            string           name      = BarcodeEngine.GetSymbologyFriendlyName(symbology);

            _sampleSymbologiesRasterImage.Page = (int)symbology;

            if (_itemPen == null)
            {
                _itemPen = new Pen(Brushes.Black, 2);
            }

            e.Graphics.DrawRectangle(_itemPen, rc);
            e.Graphics.FillRectangle(Brushes.White, rc);

            RasterPaintProperties paintProperties = RasterPaintProperties.Default;

            if (RasterSupport.IsLocked(RasterSupportType.Document))
            {
                paintProperties.PaintDisplayMode = RasterPaintDisplayModeFlags.Bicubic;
            }
            else
            {
                paintProperties.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray;
            }

            LeadRect imageRect = new LeadRect(rc.X + 2, rc.Y + 2, rc.Width - 4, rc.Height * 2 / 3);

            imageRect = RasterImage.CalculatePaintModeRectangle(
                _sampleSymbologiesRasterImage.ImageWidth,
                _sampleSymbologiesRasterImage.ImageHeight,
                imageRect,
                RasterPaintSizeMode.FitAlways,
                RasterPaintAlignMode.CenterAlways,
                RasterPaintAlignMode.CenterAlways);

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e.Graphics.FillRectangle(SystemBrushes.Highlight, rc);
                RasterImagePainter.Paint(_sampleSymbologiesRasterImage, e.Graphics, imageRect, paintProperties);
                e.Graphics.DrawRectangle(Pens.Black, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height);
                e.Graphics.DrawString(name, Font, SystemBrushes.HighlightText, rc, _stringFormat);
            }
            else
            {
                e.Graphics.FillRectangle(SystemBrushes.Control, rc);
                RasterImagePainter.Paint(_sampleSymbologiesRasterImage, e.Graphics, imageRect, paintProperties);
                e.Graphics.DrawRectangle(Pens.Black, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height);
                e.Graphics.DrawString(name, Font, SystemBrushes.ControlText, rc, _stringFormat);
            }
        }