private RasterImage CreateAttachmentImage(ImageViewer imageViewer)
        {
            // Get the attachment image from the resource
            Bitmap icon = Properties.Resources.Attachment;

            using (RasterImage image = RasterImageConverter.ConvertFromImage(icon, ConvertFromImageOptions.None))
            {
                // Resize the image to be the same as width as image viewer thumbnails with original height
                int desiredWidth;
                if (_documentViewer.Thumbnails != null)
                {
                    desiredWidth = _documentViewer.Thumbnails.MaximumSize.Width;
                }
                else
                {
                    desiredWidth = image.ImageWidth;
                }

                var         destRect        = new LeadRect(0, 0, desiredWidth, image.ImageHeight);
                RasterImage attachmentImage = RasterImage.Create(destRect.Width, destRect.Height, 32, 96, RasterColor.Black);
                new SetAlphaValuesCommand(0x00).Run(attachmentImage);

                LeadRect imageRect = RasterImage.CalculatePaintModeRectangle(
                    image.ImageWidth,
                    image.ImageHeight,
                    destRect,
                    RasterPaintSizeMode.Fit,
                    RasterPaintAlignMode.Center,
                    RasterPaintAlignMode.Center);

                new CombineFastCommand(attachmentImage, imageRect, LeadPoint.Empty, Leadtools.ImageProcessing.CombineFastCommandFlags.SourceCopy).Run(image);
                return(attachmentImage);
            }
        }
예제 #2
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);
                }
            }
        }
예제 #3
0
        private void _printDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            // Get the print document object
            PrintDocument document = sender as PrintDocument;

            SvgDocument svgDoc        = _viewer.DocumentList[_currentPrintPageNumber - 1].Document;
            var         svgResolution = svgDoc.Bounds.Resolution;
            var         svgBounds     = svgDoc.Bounds.Bounds;
            // Get page size in pixels
            var pixelSize = LeadSizeD.Create(svgBounds.Width, svgBounds.Height);

            using (Bitmap bitmap = new Bitmap((int)pixelSize.Width, (int)pixelSize.Height, PixelFormat.Format32bppPArgb))
            {
                // Convert to DPI
                var size = LeadSizeD.Create(pixelSize.Width * bitmap.HorizontalResolution / svgResolution.Width, pixelSize.Height * bitmap.VerticalResolution / svgResolution.Height).ToLeadSize();
                // Fit in the margin bounds
                var destRect = LeadRect.Create(e.MarginBounds.X, e.MarginBounds.Y, e.MarginBounds.Width, e.MarginBounds.Height);
                destRect = RasterImage.CalculatePaintModeRectangle(
                    size.Width,
                    size.Height,
                    destRect,
                    RasterPaintSizeMode.Fit,
                    RasterPaintAlignMode.Center,
                    RasterPaintAlignMode.Center);

                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    using (var engine = RenderingEngineFactory.Create(g))
                    {
                        var options = new SvgRenderOptions();
                        options.Bounds = svgBounds;
                        svgDoc.Render(engine, options);
                    }
                }
                e.Graphics.DrawImage(bitmap, destRect.X, destRect.Y, destRect.Width, destRect.Height);
            }

            // Go to the next page
            _currentPrintPageNumber++;

            // Inform the printer whether we have more pages to print
            if (_currentPrintPageNumber <= document.PrinterSettings.ToPage)
            {
                e.HasMorePages = true;
            }
            else
            {
                e.HasMorePages = false;
            }
        }
예제 #4
0
        /// <summary>
        /// Save the current image with stamp
        /// </summary>
        private void _miFileSaveWithStamp_Click(object sender, System.EventArgs e)
        {
            try
            {
                // take the destination JPEG file name
                SaveFileDialog sfd = new SaveFileDialog();
                // the destination image format should be JPEG.
                sfd.Filter = "JPEG(*.jpg;*.jpeg)|*.jpg;*.jpeg";
                if (sfd.ShowDialog(this) == DialogResult.OK)
                {
                    // Enable saving with stamp
                    _codecs.Options.Jpeg.Save.SaveWithStamp     = true;
                    _codecs.Options.Jpeg.Save.StampBitsPerPixel = 24;

                    // Calculate the stamp size (fit it in a 128 by 128 pixels)
                    LeadRect rc = RasterImage.CalculatePaintModeRectangle(
                        _viewerImage.Image.ImageWidth,
                        _viewerImage.Image.ImageHeight,
                        new LeadRect(0, 0, 128, 128),
                        RasterPaintSizeMode.Fit,
                        RasterPaintAlignMode.Near,
                        RasterPaintAlignMode.Near);

                    _codecs.Options.Jpeg.Save.StampWidth  = rc.Width;
                    _codecs.Options.Jpeg.Save.StampHeight = rc.Height;

                    // save the image as JPEG with stamp with the closest bits per pixel
                    _codecs.Save(_viewerImage.Image, sfd.FileName, RasterImageFormat.Jpeg, 0);
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
            finally
            {
                UpdateMyControls();
            }
        }
예제 #5
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);
            }
        }
예제 #6
0
        // Optionally resizes the image before saving it (always preserving the original aspect ratio)
        public static void ResizeImage(RasterImage image, int width, int height)
        {
            SizeCommand sizeCommand;
            int         resizeWidth;
            int         resizeHeight;

            RasterSizeFlags flags = RasterSizeFlags.Resample;

            if (image.BitsPerPixel == 1)
            {
                flags |= RasterSizeFlags.FavorBlack;
            }

            // First check if its a FAX image (with different resolution), if so, resize it too
            if (image.XResolution != 0 && image.YResolution != 0 && Math.Abs(image.XResolution - image.YResolution) > 2)
            {
                // Yes
                if (image.XResolution > image.YResolution)
                {
                    resizeWidth  = image.ImageWidth;
                    resizeHeight = (int)((double)image.ImageHeight * (double)image.XResolution / (double)image.YResolution);
                }
                else
                {
                    resizeHeight = image.ImageHeight;
                    resizeWidth  = (int)((double)image.ImageWidth * (double)image.YResolution / (double)image.XResolution);
                }

                sizeCommand = new SizeCommand(resizeWidth, resizeHeight, flags);
                sizeCommand.Run(image);

                image.XResolution = Math.Max(image.XResolution, image.YResolution);
                image.YResolution = image.XResolution;
            }

            // Check user resize options, and resize only if needed
            if ((width == 0 && height == 0) ||
                (image.ImageWidth <= width && image.ImageHeight <= height))
            {
                return;
            }

            resizeWidth  = width;
            resizeHeight = height;

            // If width or height is 0, means the other is a fixed value and the missing value must be calculated
            // saving the aspect ratio
            if (resizeHeight == 0)
            {
                resizeHeight = (int)((double)image.ImageHeight * (double)resizeWidth / (double)image.ImageWidth + 0.5);
            }
            else if (resizeWidth == 0)
            {
                resizeWidth = (int)((double)image.ImageWidth * (double)resizeHeight / (double)image.ImageHeight + 0.5);
            }

            // Calculate the destination size
            LeadRect rc = new LeadRect(0, 0, resizeWidth, resizeHeight);

            rc = RasterImage.CalculatePaintModeRectangle(
                image.ImageWidth,
                image.ImageHeight,
                rc,
                RasterPaintSizeMode.Fit,
                RasterPaintAlignMode.Near,
                RasterPaintAlignMode.Near);

            image.ChangeViewPerspective(RasterViewPerspective.TopLeft);
            sizeCommand = new SizeCommand(rc.Width, rc.Height, flags);
            sizeCommand.Run(image);

            // Note, if the image was 1BPP, ScaleToGray converts it to 8, the format of the returned image is dealt with
            // in PrepareToSave

            // Since we resized the image, the original DPI is not correct anymore
            image.XResolution = 96;
            image.YResolution = 96;
        }