Ejemplo n.º 1
0
        void _rasterImageList_PostRender(object sender, Leadtools.Controls.ImageViewerRenderEventArgs e)
        {
            for (int i = 0; i < _rasterImageList.Items.Count; i++)
            {
                ImageViewerItem item = _rasterImageList.Items[i];

                LeadRectD itemLeadRect  = _rasterImageList.GetItemBounds(item, ImageViewerItemPart.Item);
                Rectangle itemRect      = new Rectangle((int)itemLeadRect.X, (int)itemLeadRect.Y, (int)itemLeadRect.Width, (int)itemLeadRect.Height);
                LeadSize  itemImageSize = _rasterImageList.GetItemImageSize(item, false);

                LeadRect imageRect = new LeadRect(
                    itemRect.Left + (itemRect.Width - itemImageSize.Width) / 2,
                    itemRect.Top + (itemRect.Height - itemImageSize.Height) / 2,
                    itemImageSize.Width,
                    itemImageSize.Height);

                itemLeadRect = ImageViewer.GetDestinationRectangle(item.Image.ImageWidth, item.Image.ImageHeight, imageRect, ControlSizeMode.None, ControlAlignment.Near, ControlAlignment.Near).ToLeadRectD();

                var destRect = LeadRectD.Create(itemLeadRect.X, itemLeadRect.Y, itemLeadRect.Width * 720.0 / 96.0, itemLeadRect.Height * 720.0 / 96.0);

                destRect.X = 0.0;
                destRect.Y = 0.0;

                //Get the graphic object from the item's image to draw (burn) annotations on it.
                Leadtools.Drawing.RasterImageGdiPlusGraphicsContainer GdiPlusGraphicsContainer = new RasterImageGdiPlusGraphicsContainer(item.Image);
                Graphics g = GdiPlusGraphicsContainer.Graphics;

                // Use anti-aliasing
                g.SmoothingMode = SmoothingMode.AntiAlias;

                // Now draw the annotation s on this rectangle
                if (_automationManager != null && _automation.Containers.Count > 0 && _automation.Containers.Count > i)
                {
                    AnnContainer container = _automation.Containers[i];

                    //Clear the old painting
                    g.Clear(Color.White);

                    //Burn the current annotations to the image list item
                    if (container != null)
                    {
                        AnnWinFormsRenderingEngine engine = new AnnWinFormsRenderingEngine();
                        engine.Resources = _automationManager.Resources;

                        // Save its visible state and set it to true (it is false if viewer is in single mode)
                        bool containerIsVisible = container.IsVisible;
                        container.IsVisible = true;

                        engine.Attach(container, g);
                        engine.BurnToRectWithDpi(destRect, 96, 96, 96, 96);
                        engine.Detach();

                        if (container.IsVisible != containerIsVisible)
                        {
                            container.IsVisible = containerIsVisible;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void ViewerForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Color drawColor;

            if (_viewer.Image != null)
            {
                if (_viewer.Image.Width >= 150 && _viewer.Image.Height >= 150)
                {
                    _viewer.Image = _tempImage.CloneAll();

                    using (RasterImageGdiPlusGraphicsContainer container = new RasterImageGdiPlusGraphicsContainer(_viewer.Image))
                    {
                        // Create string to draw.
                        String drawString = "";


                        if (StandardOptions.Added)
                        {
                            drawString += " Status : ADDED\n";
                            drawString += " Index: ";
                            drawString += StandardOptions.PageNumber;
                            if (!StandardOptions.NOMRC)
                            {
                                drawString += "\n";
                                drawString += " Input Quality: ";

                                switch (StandardOptions.InputImageComboSel)
                                {
                                case 0:
                                    drawString += "Auto";
                                    break;

                                case 1:
                                    drawString += "Noisy";
                                    break;

                                case 2:
                                    drawString += "Scanned";
                                    break;

                                case 3:
                                    drawString += "Printed";
                                    break;

                                case 4:
                                    drawString += "Computer Generated";
                                    break;

                                case 5:
                                    drawString += "Photo";
                                    break;

                                case 6:
                                    drawString += "User Defined";
                                    break;
                                }

                                drawString += "\n Output Quality : ";
                                switch (StandardOptions.OutputImageComboSel)
                                {
                                case 0:
                                    drawString += "Auto";
                                    break;

                                case 1:
                                    drawString += "Poor";
                                    break;

                                case 2:
                                    drawString += "Average";
                                    break;

                                case 3:
                                    drawString += "Good";
                                    break;

                                case 4:
                                    drawString += "Excellent";
                                    break;

                                case 5:
                                    drawString += "User Defined";
                                    break;
                                }
                            }
                            drawColor = Color.Green;
                        }
                        else
                        {
                            drawString += " Status : NOT ADDED";
                            drawColor   = Color.Red;
                        }

                        // Create font and brush.
                        int fontSize = 12;
                        LinearGradientBrush gradientBrush;
                        Font       drawFont  = new Font("Arial", fontSize, FontStyle.Bold, GraphicsUnit.Pixel);
                        SolidBrush drawBrush = new SolidBrush(Color.Black);

                        // Set format of string.
                        SizeF size = container.Graphics.MeasureString(drawString, drawFont);
                        Pen   pen  = new Pen(drawColor, 0);
                        container.Graphics.DrawRectangle(pen, 0, 0, _viewer.Image.Width, size.Height);

                        _drawRect = new RectangleF(0, 0, _viewer.Image.Width, size.Height);

                        StringFormat drawFormat = new StringFormat();
                        drawFormat.Alignment = StringAlignment.Center;
                        gradientBrush        = new LinearGradientBrush(_drawRect, drawColor, Color.White, LinearGradientMode.ForwardDiagonal);

                        container.Graphics.FillRectangle(gradientBrush, _drawRect);

                        container.Graphics.DrawString(drawString, drawFont, drawBrush, _drawRect);//,drawFormat);
                    }
                }
            }
        }