在按钮单击时显示图像中标记的多个区域 [英] show multiple regions marked in an image on button click

查看:69
本文介绍了在按钮单击时显示图像中标记的多个区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在图像上标记了多个区域,并将其坐标存储在一个数组中。现在我想在按钮点击时显示我在图像上标记的区域。

例如。我在图像上标记了5个区域,我想在按钮单击时显示图像上同时标记的所有5个区域。至于现在,我只是标记了第五个区域。

我无法发布代码,因为它是项目的一部分,因此包含许多其他内容。

提前谢谢。

I have marked multiple areas on an image and stored its coordinates in an array. Now i want to show the regions I have marked on the image on button click.
For eg. I have marked 5 regions on the image, I want to show all the 5 regions marked at the same time on the image on button click. As for now,I am just getting the 5th region marked.
I can't post the code , as it is the part of a project, thus containing many other things.
Thanks in advance.

推荐答案

我个人使用矩形列表(矩形)来保存区域。另外两个变量用于创建(new_rectangle)和绘制(path_rectangles)矩形。



Personally, I'd use a List of Rectangles (rectangles) to save the "regions". The other two variables are used to create (new_rectangle) and draw (path_rectangles) the rectangles.

Rectangle                 new_rectangle = new Rectangle ( );
Rectangle [ ]             path_rectangles;
List <Rectangle>          rectangles = new List < Rectangle > ( );





您的MouseDown事件处理程序必须填充new_rectangle的左上角。





Your MouseDown event handler must populate the upper left corner of new_rectangle.

new_rectangle.X = e.X;
new_rectangle.Y = e.Y;
new_rectangle.Width = 0;
new_rectangle.Height = 0;





您的MouseUp事件处理程序必须填充new_rectangle的宽度和高度,并将new_rectangle添加到矩形列表中。





Your MouseUp event handler must populate the width and height of new_rectangle and also add the new_rectangle to the List of Rectangles.

new_rectangle.Width = Math.Abs ( new_rectangle.X - e.X );
new_rectangle.Height = Math.Abs ( new_rectangle.Y - e.Y );
rectangles.Add ( new_rectangle );





按钮点击事件处理程序然后将矩形列表转换为矩形数组,然后调用Invalidate方法。





The button click event handler would then convert the List of rectangles into an array of rectangles and then invoke the Invalidate method.

path_rectangles = rectangles.ToArray ( );
this.Invalidate ( );





最后,你的OnPaint事件处理程序看起来像:





Finally, your OnPaint event handler would look something like:

protected override void OnPaint ( PaintEventArgs e )
    {
    GraphicsPath path;

    base.OnPaint ( e );

    path = new GraphicsPath ( );
    path.AddRectangles ( path_rectangles );
    e.Graphics.DrawPath ( Pens.Black, path );
    }





我指出GraphicsPath对象可以由多边形组成,所以你的行不一定需要形式矩形。



请注意,您必须解决初始点位于最终点下方或右侧的问题。我给出的解决方案不考虑这个。



I point out that the GraphicsPath object can be composed of polygons so your lines need not necessarily form rectangles.

Note that you must solve the problem of the initial point being below or to the right of the final point. The solution that I give does not consider this.


这篇关于在按钮单击时显示图像中标记的多个区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆