【C# GDI+绘制图片问题!!!!!!】

我用Graphics 绘制图片,刚开始为什么绘制不出来呢,就是没有显示,当循环多次后台显示图片。
求解答,完整代码如下:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;

namespace 多线程带参数
{
class Form1 : Form
{
private PictureBox pic;
Graphics g;
private int Bit_X,Loca;
Bitmap bit;

public Form1()
{
Initialize();

}

private void Initialize()
{
pic = new PictureBox();
pic.Size = new Size(32, 48);
pic.Location = new Point(0,0);

g = pic.CreateGraphics();

this.SuspendLayout();
this.Controls.Add(pic);

this.Size = new Size(500, 280);
this.StartPosition = FormStartPosition.CenterScreen;
this.ResumeLayout();


bit = new Bitmap("MAN.png");
Loca=Bit_X = 0;
Thread thread1 = new Thread(new ThreadStart(ManMove));
thread1.IsBackground = true;
thread1.Start();
CheckForIllegalCrossThreadCalls = false;
}

private void ManMove()
{
while (pic.Location.X < 500 - 32)
{
//bit.RotateFlip(RotateFlipType.Rotate90FlipY);
Rectangle rect = new Rectangle(Bit_X, 96, 32, 48);
Rectangle rectLoca=new Rectangle(0, 0, 32, 48);
g.DrawImage(bit, rectLoca, rect, GraphicsUnit.Pixel);

Thread.Sleep(5000);
// Bit_X += 32;
if (Bit_X >= 192)
Bit_X = 0;
// g.Clear(pic.BackColor);
// pic.Location =new Point(Loca+=5,0);
}
MessageBox.Show("Exit");
}
}
}
...全文
159 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
哎,我人品问题,图片本来就没那么大我却调用了超过它的宽度。

虽然楼上回答没能解决问题,但回答了总比没回答好,全给你了。
  • 打赏
  • 举报
回复
CheckForIllegalCrossThreadCalls = false;这种方式并不好还会留下隐患
声明一个开始绘制和绘制完成的事件来通知主线程
  • 打赏
  • 举报
回复
快点帮帮忙吧,大哥大姐们!

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧