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

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

问题描述

我正在使用此代码在位图中创建图像.
下面的代码将整个位图设置为白色图像.

I am using this code to create a image in bitmap.
The below code sets the entire bitmap into white image.

for (i = 0; i < Height; i++)
               for (j = 0; j < Width; j++)
                   BufferImage.SetPixel(j, i, Color.White);



我的想法是正确的吗?



Is what I am thinking is correct?

void DrawingPanel1_Paint(object Sender, PaintEventArgs e)
       {
           Graphics g = e.Graphics;
           g.DrawImage(BufferImage,0,0);
       }



为什么使用此代码?
在我的应用程序中,每次刷新控件时都会调用此函数.当e被调用时,它会是什么?

这些是做什么的
e.Graphics
g.DrawImage(BufferImage,0,0)



Why this code is used?
In my application this function is getting called every time when my controls are refreshed. What will in e, when it is called?

what does these do
e.Graphics
g.DrawImage(BufferImage,0,0)

推荐答案

您确实应该为自己做些阅读.

您似乎想知道什么是Graphics对象以及它的作用.因此,请在此处 [ ^ ].

简而言之,Graphics是一个类,使您可以在BitmapControl上绘制.

您的第一个代码示例应该可以运行,但是相对较慢.如果可能的话,您应该用类似的代替它

You really should do a little reading for yourself.

You seem to want to know what a Graphics object is and what it does. So take a look at the documentation here[^].

Put very simply a Graphics is a class that enables you to draw on a Bitmap or Control.

Your first code sample should work but will be comparatively slow. If possible you should replace it with something like

using (Graphics g = Graphics.FromImage(BufferImage))
{
  g.Clear(Colors.White);
}



这样会更快.

第二个片段中的e.Graphics是一个Graphics对象,无论使用哪种控件(我假设为Panel),该对象都将在DrawingPanel1上进行绘制.
对于DrawImage,为什么不从我之前给您的链接中自己阅读它?您将通过这种方式学到更多.



which will be far quicker.

The e.Graphics in the second snippet is a Graphics object that will do all its drawing on DrawingPanel1 whatever sort of control that is (I assume a Panel)

For DrawImage, why not read it for yourself from the link I gave you earlier? You will learn far more that way.


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

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