C#中的g.DrawImage问题,请教一下,为啥ShowPic()不显示图片?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#中的g.DrawImage问题,请教一下,为啥ShowPic()不显示图片?相关的知识,希望对你有一定的参考价值。

public partial class Form1 : Form public Form1() InitializeComponent(); ShowPic(); private void Form1_Paint(object sender, PaintEventArgs e) Bitmap bmp = new Bitmap("e:/03.jpg"); Graphics g = this.CreateGraphics(); //画像描绘 g.Clear(Color.White); g.DrawImage(bmp, 0, 0, 62, 71); private void ShowPic() Bitmap bmp = new Bitmap("e:/03.jpg"); Graphics g = this.CreateGraphics(); //画像描绘 g.Clear(Color.White); g.DrawImage(bmp, new System.Drawing.Rectangle(70,70, 62, 71));

参考技术A 由于Winform是不断重绘的,包括最大化、最小化、移动窗体等操作,Winform都会不断的重绘自己,所以在Load时画图,只闪现了一下,然后又被重绘了。
在Paint里做到画图,意思就是重绘时都调用你的绘图方式,所以可以正常显示。
有点需要指出的:在你的Paint方法里,Graphics可以不由CreateGraphics产生,可以由参数e里的Graphics

以上是关于C#中的g.DrawImage问题,请教一下,为啥ShowPic()不显示图片?的主要内容,如果未能解决你的问题,请参考以下文章

关于Jpanel中g.drawImage函数bug调试。。。

关于Jpanel中g.drawImage函数bug调试。。。

java中 g.drawImage()方法如何使用

请教:C# WebService调用Java WebService(返回Json类型数据) ,为啥接收为null

怎样删除winform中由Graphics g = this.CreateGraphics(); g.DrawImage(img, (int)L.Left, (int)L.Top, 30

LayerUI、g.drawImage 下划线