Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My requirement is highlighting the text on Image while drawing the rectangular on Image Text .I have tried different ways but Color is not applying to Text.Please help me Thank you.

What I have tried:

C#
protected void HighlightImageText(ImageViewerRubberBandEventArgs e)
        {

            int left = 0;
            int right = 0;
            int top = 0;
            int bottom = 0;
            int PAX = -1, PAY = -1, PBX = -1, PBY = -1, PCX = -1, PCY = -1, PDX = -1, PDY = -1;
            LeadRect selectedImageRectangle = new LeadRect(0, 0, 0, 0);
            selectedImageRectangle = this._imageViewer.ConvertRect(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image,
                                                            LeadRect.FromLTRB(e.Points[0].X, e.Points[0].Y, e.Points[1].X, e.Points[1].Y));

            left = selectedImageRectangle.Left;
            right = selectedImageRectangle.Right;
            top = selectedImageRectangle.Top;
            bottom = selectedImageRectangle.Bottom;
            PAX = selectedImageRectangle.X;
            PAY = selectedImageRectangle.Y;
            PBX = PAX + selectedImageRectangle.Width;
            PBY = PAY;
            PCX = PAX;
            PCY = PAY + selectedImageRectangle.Height;
            PDX = PBX;
            PDY = PCY;


            try
            {
                if (_annManager == null)
                {
                    _annManager = new AnnAutomationManager();
                    _annManager.CreateDefaultObjects();
                }
                _automationControl = new ImageViewerAutomationControl();
              //  if (_annAutomation == null)
                {
                    _annAutomation = new AnnAutomation(_annManager, _automationControl);
                    _annAutomation.Active = true;
                }

                Leadtools.Annotations.AnnContainer container = new Leadtools.Annotations.AnnContainer();

                left = PAX;
                if (left > PBX) left = PBX;
                if (left > PCX) left = PCX;
                if (left > PDX) left = PDX;

                top = PAY;
                if (top > PBY) top = PBY;
                if (top > PCY) top = PCY;
                if (top > PDY) top = PDY;

                right = PDX;
                if (right < PCX) right = PCX;
                if (right < PBX) right = PBX;
                if (right < PAX) right = PAX;

                bottom = PDY;
                if (bottom < PCY) bottom = PCY;
                if (bottom < PBY) bottom = PBY;
                if (bottom < PAY) bottom = PAY;

                if (left != -1 && right != -1 && top != -1 && bottom != -1)
                {
                    float width = 0;
                    float height = 0;

                    width = System.Math.Abs(right - left);
                    height = System.Math.Abs(bottom - top);

   
                    double inch = 720.0;
                    Leadtools.Annotations.Core.AnnHiliteObject hiliteObj = new Leadtools.Annotations.Core.AnnHiliteObject();
                    hiliteObj.Points.Add(LeadPointD.Create(1 * inch, 1 * inch));
                    hiliteObj.Points.Add(LeadPointD.Create(2 * inch, 1 * inch));
                    hiliteObj.Points.Add(LeadPointD.Create(2 * inch, 2 * inch));
                    hiliteObj.Points.Add(LeadPointD.Create(1 * inch, 2 * inch));
                    hiliteObj.Rect = LeadRectD.Create(left, top, width, height);
                   
                    hiliteObj.HiliteColor = "Yellow";
                    hiliteObj.RenderedObjectBounds = LeadRectD.Create(left, top, width, height);
                    hiliteObj.Fill = AnnSolidColorBrush.Create("Yellow");
                    hiliteObj.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Yellow"), LeadLengthD.Create(1));
                    hiliteObj.Bounds.ContainsRect(LeadRectD.Create(left, top, width, height));
                   // _annManager.Objects.Clear();
                 //   _annAutomation.Containers.Clear();
                    _annAutomation.Container.Children.Add(hiliteObj);
                    _annAutomation.ActiveContainer.Children.Add(hiliteObj);
                    AnnRectangleObject rectObj = new AnnRectangleObject();
                    rectObj.Rect = LeadRectD.Create(left, top, width, height);
                    rectObj.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Blue"), LeadLengthD.Create(1));
                    rectObj.Fill = AnnSolidColorBrush.Create("Yellow");
                    rectObj.RenderedObjectBounds= LeadRectD.Create(left, top, width, height); ;
                    _annAutomation.ActiveContainer.Children.Add(rectObj);

                    this._imageViewer.Invalidate();
                    // TODO: check following cumbersome logic to refresh the image
                    Size imgSize = this._imageViewer.Size;
                    Size newImgSize = imgSize;
                    newImgSize.Height = newImgSize.Height - 1;
                    this._imageViewer.Size = newImgSize;
                    this._imageViewer.Size = imgSize;

                }
            }
            catch (Exception ex)
            {
                //  ErrorHandler.ProcessMessage(this, e);
            }
        }
Posted
Updated 1-Sep-18 2:47am
v2
Comments
Graeme_Grant 1-Sep-18 6:50am    
You are best off asking your question at the 3rd party tool's support area: LEADTOOLS Technical Support[^]
Slacker007 1-Sep-18 8:44am    
I have worked with Lead Tools products for a couple of years in the past, and I know they have a very good demo project listing with each install. I would check for the correct demo project that is doing what you want to do and get an idea from that. Also, as Graeme_Grant pointed out, you should go to LeadTools site and look at their knowledge base and FAQ. That helped me out a bunch in the past.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900