在图像上绘制形状 [英] Drawing shapes on an image

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

问题描述

我想在图片框中打开一个图像文件(.JPG,.BMP等),而不是想在那些图像上创建形状,那么可以使用DrawTools项目吗?

I want to open a image file(.JPG,.BMP etc) in a Picture box and than i want to create shapes on that images so is it possible with DrawTools project?

推荐答案

首先,我们甚至不想使用 PictureBox



此控件冗余度很低,应该仅用于简化最简单的情况,例如显示一些静态图像。在大多数更复杂的情况下,它只会带来麻烦并使用资源而不会产生任何回报。您应该使用自己的图形渲染,这非常简单。请看我过去的答案:

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

在C#中绘制一个矩形 [ ^ ],

在图片框中附加图片 [ ^ ]。



现在,要绘制位图,你需要从这个bitma获取 System.Drawing.Graphics 的实例页。具体如下:

http:// msdn。 microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx [ ^ ]。



现在,您可以在平时使用此图像方式,绘制位图。



再次,彻底检查你的设计。如果绘制位图的唯一目的是在屏幕上绘图,那么你甚至不需要位图。如果您只是使用双缓冲,则位图将在内部用于避免闪烁。关于进一步的渲染细节,请参阅我过去的答案:

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

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

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

如何加速我的vb.net应用程序? [ ^ ]。



如果你仍需要绘制位图(例如,如果你需要将图形保存为位图),按照我之前的解释。但如果您需要同时绘制(位图,屏幕,也可能是打印机),请注意它们都使用 System.Drawing.Graphis 。使用 Graphics 作为参数编写一些通用方法,以及其他参数,例如size。这样,您就可以从特定媒体中抽象出渲染。



-SA
First of all, don''t even play with the idea of using PictureBox.

This control is poorly redundant and should be used only to simplify the simplest cases, such as showing some static image. In most more complex cases, it only presents hassles and use resources giving nothing in return. You should use your own rendering of graphics, which is really simple. Please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].

Now, to draw on a bitmap, you need to obtain the instance of System.Drawing.Graphics from this bitmap. This is how:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx[^].

Now, you can use this image in a usual way, to draw on a bitmap.

Again, check your design thoroughly. If the only purpose of drawing on a bitmap was drawing on screen, you don''t even need a bitmap. The bitmap will be used internally to avoid flicker, if you simply use double buffering. On further rendering detail, please see my past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
How to speed up my vb.net application?[^].

If you still need to draw on a bitmap (for example, if you need to save graphics as bitmap), do as I explained before. But if you need to draw on both (bitmap, screen, maybe printer as well), pay attention that they all use System.Drawing.Graphis. Write some universal method using Graphics as a parameter, with other parameters, such as size. This way, you can abstract out your rendering from a particular media.

—SA


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

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