需要咨询-如何编写绘图程序 [英] Need advise - How to write a drawing program

查看:139
本文介绍了需要咨询-如何编写绘图程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想编写一个程序,使用户能够绘制诸如圆形,三角形,矩形等的几何形状.
我还希望能够拖放或调整先前绘制的形状.

1)我想在面板中绘制形状.看起来合理吗?
2)说我画了几种形状.然后,我想调整第一个绘制形状的大小.如何确定第一个形状已单击?

谢谢!

Hi,

I would like to write a program that enable user to draw geometric shapes like circles, triangles, rectangles and so on.
I would like also to be able to drag and drop or resize a shape that was previously drawn.

1) I thought to draw the shapes inside a Panel. Does it seems reasonable ?
2) Say I drew several shapes. Then I want to resize the first drawn shape. How can I identify that the first shape was clicked ?

Thanks !

推荐答案

看看 [ ^ ]很酷的文章.我相信这可以对您有很大帮助! :)

[来自Brady Kelly的2c]该文章描述了基于形状或矢量的绘图模型,它非常适合您的需求.无需担心像素.
Have a look at this[^] cool article. I believe that it could help you a lot! :)

[2c from Brady Kelly] That article describes a shape or vector based drawing model, which is perfect for what you need. There is no need to worry about pixels.



谢谢您的链接,但是我想要的只是了解这个想法,而不是阅读大量的代码.
我确实有一些在GDI +中绘制图形的经验.
此时,我只想了解例如调整大小/移动圆的想法.
画完一个圆之后,它变成了位图的一部分.当然,我确实将圈子的详细信息保存在其他对象中.
但是我不明白如何实现以下目标:
当鼠标悬停在圆圈上时,将选择圆圈,然后使用一些键使用户能够调整其大小/将其移动.
我怎么知道鼠标在圆上?
我需要检查鼠标坐标与所有圆形像素坐标吗?
我正在寻找更简单的解决方案....
Hi,
Thank you for the link, but all I want is to understand the idea rather than reading a lot of code.
I do have some experience with drawing graphics in GDI+.
At this point I just want to understand the idea of resizing/moving a circle for example.
After I draw a circle, it becomes a part of a Bitmap. Of course, I do save circle''s details in some other object.
But what I don''t understand is how to implement the following:
when the mouse is over the circle, the circle is chosen, and then using some key enables the user to resize/move it.
How can I know that the mouse is over the circle ?
Do I need to check the mouse coordinates vs all circle pixel coordinates ?
I''m looking for simpler solution....


通常,您将每种形状存储在内存中,并且每次添加新形状时,都将所有这些形状重新绘制到新的位图上(并丢弃旧的).

要检测鼠标悬停在哪个形状上,简单的方法是检查鼠标在该像素处与哪个形状发生碰撞,然后选择最顶部的形状.

但是,如果形状很多,则渲染伪位图可能会更快,该伪位图包含每个像素的颜色以外的信息.例如,您可以存储渲染该像素的形状.因此,您只需要在该伪位图中找到鼠标坐标,然后知道哪种形状呈现了该像素.

此外,您可能可以使用该伪位图将新形状渲染到位图,而不必重新绘制所有形状.您可以仅应用新形状,并确保不覆盖新形状上方的形状的任何像素.如果必须修改现有形状(例如旋转形状),只需找到其所有像素,将其删除,然后在这些像素处渲染所有其他形状(然后重新绘制修改后的形状) ).

还有其他方法,但是应该可以给您一些想法.
Typically, you would store each shape in memory and each time a new shape is added, you redraw all those shapes to a new bitmap (and discard the old one).

To detect which shape a mouse is over, the simple way is to check which shapes it collides with at that pixel, then select the top most shape.

However, if there are a lot of shapes, it might be faster to render a pseudo-bitmap that contains information other than color for each pixel. For example, you could store which shape rendered that pixel. So, you''d just have to find the mouse coordinates in that pseudo-bitmap and then you''d know which shape rendered that pixel.

Also, you might be able to use that pseudo-bitmap to render new shapes to the bitmaps without having to redraw all the shapes. You could just apply the new shape, making sure not to overwrite any pixels for shapes that are above the new shape. And if you have to modify an existing shape (e.g., to rotate it), you just find all it''s pixels, remove them, then render all the other shapes at those pixels (then you''d redraw the shape you modified).

There are other ways of doing that, but those should give you some ideas.


这篇关于需要咨询-如何编写绘图程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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