请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

x1212chf

初级会员

17

主题

35

帖子

355

积分

初级会员

积分
355

活字格认证

x1212chf
初级会员   /  发表于:2019-4-22 09:56  /   查看:3155  /  回复:1
本帖最后由 x1212chf 于 2019-4-22 14:27 编辑

Leadtool 19
在AnnAutomation中添加AnnPolylineObject,移动AnnPolylineObject,获取AnnPolylineObject的位置信息,并安装其位置信息分割图片,现在的问题是如何坐标转换,获取到AnnPolylineObject的位置,非常感谢!
已查到处理方法,感谢!

主要代码如下:

private ImageViewer viewer;
private AnnAutomation automation;
private LeadRect currentDrawRectangle = LeadRect.Empty;

private void AnnotationsDemo_Load(object sender, EventArgs e)
        {
            viewer = new ImageViewer();
            viewer.Dock = DockStyle.Fill;

            ImageViewerAutomationControl automationControl = new ImageViewerAutomationControl();
            automationControl.ImageViewer = viewer;

            // initialize a new RasterCodecs object
            RasterCodecs codecs = new RasterCodecs();
            // load the main image into the viewer
            viewer.Image = codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp");

            // initialize the interactive mode for the viewer
            AutomationInteractiveMode automationInteractiveMode = new AutomationInteractiveMode();
            automationInteractiveMode.AutomationControl = automationControl;

            // add the interactive mode to the viewer
            viewer.InteractiveModes.BeginUpdate();
            viewer.InteractiveModes.Add(automationInteractiveMode);
            viewer.InteractiveModes.EndUpdate();

            viewer.PostRender += Viewer_PostRender;

            if (viewer.Image != null)
            {
                // create and set up the automation manager
                AnnAutomationManager annAutomationManager = new AnnAutomationManager();
                annAutomationManager.RestrictDesigners = true;

                // Instruct the manager to create all of the default automation objects.
                annAutomationManager.CreateDefaultObjects();

                // initialize the manager helper and create the toolbar and add it then the viewer to the controls
                AutomationManagerHelper managerHelper = new AutomationManagerHelper(annAutomationManager);
                managerHelper.CreateToolBar();
                ToolBar toolBar = managerHelper.ToolBar;
                Controls.Add(toolBar);
                Controls.Add(viewer);
                toolBar.Visible = false;
                automation = new AnnAutomation(annAutomationManager, automationControl);
                automation.Active = true;
                automation.Container.Size = automation.Container.Mapper.SizeToContainerCoordinates(LeadSizeD.Create(viewer.Image.ImageWidth, viewer.Image.ImageHeight));
                CreateMyAutomationObjects();
                annAutomationManager.UserMode = AnnUserMode.Design;
            }
        }


      private void toolStripButton2_Click(object sender, EventArgs e)
        {
            //AnnAutomationObject obj = automation.Manager.FindObjectById(AnnObject.LineObjectId);
            //if(obj!=null)
            //{

            //}

            if (this.automation != null && automation.Container.Children.Count > 0 && automation.Container.Children[0] is AnnPolylineObject)
                {
                    try
                    {
                        if ((automation.Container.Children[0] as AnnPolylineObject).Points.Count >= 2)
                        {
                            LeadPointD p1 = (automation.Container.Children[0] as AnnPolylineObject).Points[0];
                            LeadPointD p2 = (automation.Container.Children[0] as AnnPolylineObject).Points[1];
                            /////--------------如何转换坐标??????????????????????????????
                            //p1 = viewer.ConvertPoint(viewer.ActiveItem, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, p1);
                            //p2 = viewer.ConvertPoint(viewer.ActiveItem, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, p2);
                        p1 = automation.Container.Mapper.PointFromContainerCoordinates(p1, AnnFixedStateOperations.None);
                        p2 = automation.Container.Mapper.PointFromContainerCoordinates(p2, AnnFixedStateOperations.None);

                            leadRect1 = new LeadRect(0, 0, this.imageViewer.Image.Width, (int)p1.Y);

                            currentDrawRectangle = leadRect1;
                            this.viewer.Invalidate();
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowError("出错", ex);
                    }
                }
        }

       private void CreateMyAutomationObjects()
        {
            AnnPolylineObject polyLineObj2 = new AnnPolylineObject();
            polyLineObj2.Points.Add(new LeadPointD(20, 600));
            polyLineObj2.Points.Add(new LeadPointD(1000, 600));
            polyLineObj2.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Red"), LeadLengthD.Create(3));
            polyLineObj2.IsClosed = true;
            automation.Container.Children.Add(polyLineObj2);
        }


private void ImageViewer_PostRender(object sender, ImageViewerRenderEventArgs e)
        {
            if (this.currentDrawRectangle != LeadRect.Empty)
            {
                Graphics graphics = e.PaintEventArgs.Graphics;

                using (Brush brush = new SolidBrush(Color.FromArgb(50, Color.Yellow)))
                {
                    LeadRect leadRect = this.imageViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control,
                                                            new LeadRect(currentDrawRectangle.X, currentDrawRectangle.Y, currentDrawRectangle.Width, currentDrawRectangle.Height));

                    //LeadRect leadRect = currentDrawRectangle;
                    Rectangle rectangle = new Rectangle(leadRect.X, leadRect.Y, leadRect.Width, leadRect.Height);
                    graphics.FillRectangle(brush, rectangle);
                    graphics.DrawRectangle(Pens.Yellow, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                }
            }
        }



1 个回复

倒序浏览
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-4-22 17:49:11
沙发
您好,建议您将项目打包发上来,不方便的话也可以发一个可以说明问题的小示例,我这边帮你验证
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部