在Picturebox上绘制自定义形状 [英] Drawing a custom shape on a Picturebox

查看:212
本文介绍了在Picturebox上绘制自定义形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制一个特定的形状,我发现它令人难以置信。



我设法得到一个三角形,因为我理解它背后的数学。 ..至少排序。但是我不喜欢三角形的形状,因为我想用它 - 在图像上放置一个标记作为ROI(感兴趣的区域)



I am trying to draw a specific shape and I am finding it mind boggling.

I managed to get a triangle going because I understood the maths behind it... sort off at least. But I don't like the triangle shape for what I want to use it for - placing a marker on an image as a ROI (Region Of Interest)

'Traingle points - no need to change unless to increase / decrease size of Traingle
            Points(0) = New Point(StartX, StartY)                   
            Points(1) = New Point(StartX - 20, StartY - 12)         
            Points(2) = New Point(StartX - 12, StartY - 20)         





我想要的是更像这样的东西(请原谅我原始的ascii艺术技巧)





What I want is something more like this (forgive me for my primitive ascii artistic skills)

     ____
    /
o---





形状包括(1)填充特定颜色的圆,(2)与圆相交的线(中间),(3)与底部相交的45度线和(4) )顶线。



帮助和指导将不胜感激。



T



The shape consists of (1) a circle filled with a specific colour, (2) a line intersecting with the circle (middle of), (3) a 45 degree line intersecting with the bottom and (4) top line.

Help and guidance will be appreciated.

T

推荐答案

你当然可以做到,但是根本没有理由使用 PictureBox ;这种控制纯粹是冗余的,旨在简化一些最简单的图像琐事,基本上,显示一些静态图像。如果你试图做更多的事情,任何动态的,动画的或互动的,这个课程对你没有帮助,只会迫使你浪费额外的开发时间和一些资源,不给予任何回报。请查看我过去的答案:

在其中附加图片图片框 [ ^ ],

画一个矩形C# [ ^ ],

如何从旧图纸中清除面板 [ ^ ]。



该怎么办?在您的情况下,这很容易。您可以在其他控件上渲染图形:自定义控件,甚至是 Panel 。请参阅我过去的答案以获取更多详细信息:

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ]。







另见答案:

用C#.net鼠标滚轮缩放图像 [ ^ ]。



-SA
You of course can do it, but then it makes no sense to use PictureBox at all; this control is purely, redundant designed to simplify some simplest images chores, basically, showing some static image. If you try to do anything more, anything dynamic, animated or interactive, this class won't help you, will only force you in wasting additional development time and some resources, giving nothing in return. Please see my past answers:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^].

What to do instead? This is pretty easy in your case. You can render graphics on some other control: a custom control or even, say, Panel. Please see my past answers for further detail:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].



See also another answer:
Zoom image in C# .net mouse wheel[^].

—SA


Tino Fourie写道:
Tino Fourie wrote:

例如,有一条线以某个角度绘制,我需要查看Radiants(无论它叫什么)。

For example, having a line drawn at a certain angle I need to look into Radiants (whatever it is called).

你同时是对是错。如果忽略象限(我认为这是你所谓的辐射的正确名称),如果无限值,你将失去精度或NaN(不是数字)。但是你真的需要自己考虑这些象限吗?



我还要看象限,然后我意识到如果我使用正弦我只需要它和余弦函数。但是已经考虑到这个问题的函数已经存在: System.Math.Atan2

http://msdn.microsoft.com/en-us/library/system.math.atan2% 28v = vs.110%29.aspx [ ^ ]。



在上面引用的MSDN帮助页面上查看此功能的注释;你会看到象限是如何在内部使用的。



-SA

You are right and wrong at the same time. If you ignore quadrants (I think this is a correct name for what you called "radiants"), you will get loss of precision or NaN (not a number) if infinite values. But do you actually need to consider those quadrants yourself?

I also though I have to look at quadrants, before I realized that I would only needed that if I uses sine and cosine functions. But the function which already takes this issue into account already exists: System.Math.Atan2:
http://msdn.microsoft.com/en-us/library/system.math.atan2%28v=vs.110%29.aspx[^].

Look at the notes to this function on the MSDN help page referenced above; and you will see how the quadrants are internally used.

—SA


这篇关于在Picturebox上绘制自定义形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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