关于显示图像的代码段的查询 [英] Query Regarding the code snippet of displaying image

查看:77
本文介绍了关于显示图像的代码段的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用以下代码在面板上显示图像:

For displaying image on a panel, I am using this code:

Graphics g = e.Graphics;
g.DrawImage(BufferImage, 0, 0);
g.Dispose();


推荐答案

否-请勿这样做.
由于您没有创建Graphics对象,因此处理它绝对不是您的工作-如果在您的方法之外使用它,该怎么办?

每当需要重新绘制控件时,Paint事件就会开始,并为它提供PaintEventArgs e,其中包括要绘制的图形上下文.这可能是屏幕,打印机中的一张纸或位图等.

g.DrawImage在相对于该上下文左上角的点上将图像(在这种情况下,保存在BufferImage中)绘制到给定的上下文上.因此,例如,如果上下文是面板,则g.DrawImage(BufferImage, 0, 0);会将BufferImage中的图像直接绘制到面板的左上角.

如果不确定方法的用途,请在Google上搜索它:"DrawImage C#MSDN"将带您直接了解有关它是什么以及它做什么的明确答案.在查找有关.NET属性和方法的信息时,MSDN应该是您的第一站.
No - do not do that.
Since you did not create the Graphics object it is definitely NOT your job to dispose it - what if it will be used outside your method?

The Paint event starts whenever the control needs to be re-drawn, and is give the PaintEventArgs e, which includes the graphics context to draw onto. This may be the screen, a piece of paper in the printer, or a bit map, among others.

g.DrawImage draws an image (held in this case in BufferImage) onto the given context, at a point relative to the top left hand corner of that context. So if the context is a panel, for example, g.DrawImage(BufferImage, 0, 0); would draw the image in BufferImage directly into the top left corner of the panel.

If you aren''t sure what a method does, then google it: "DrawImage C# MSDN" will take you almost directly to the definitive answer as to what it is, and what it does. MSDN should be your first stop when looking for information on .NET properties and methods.


这篇关于关于显示图像的代码段的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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