c#.net wince 内存释放问题
Bitmap bm = new Bitmap(ExeFullName + loc.ToString() + ".bmp");
pictureBox1.Image = Image.FromHbitmap(bm.GetHbitmap());
我用了一个很笨的方法演示动画,就是把很多截图放在文件夹里,然后一幅幅的显示在picturebox里面,但是在arm9的wince上总是提示内存被用完。存储空间有30M。我用了很多内存释放的方法都释放不了。哪位大侠救救火。
------解决方案--------------------
Bitmap bitmap = new Bitmap(Application.StartupPath + "\\Mygif.gif"); //定义Bitmap对象实现,并赋值为指定的GIF动画
bool current = false; //定义布尔型全局变量,并赋值为假
public void PlayImage()
{
if (!current)
{
ImageAnimator.Animate(bitmap, new EventHandler(this.OnFrameChanged)); //调用Animate方法实现动态播放GIF动画
current = true; //布尔变量current为真
}
}
private void OnFrameChanged(object o, EventArgs e)
{
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(this.bitmap, new Point(1, 1)); //绘出GIF动画
ImageAnimator.UpdateFrames(); //调用UpdateFrames方法
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
PlayImage(); //调用PlayImage方法
ImageAnimator.Animate(bitmap, new EventHandler(this.OnFrameChanged)); //播放GIF动画
}
private void button2_Click(object sender, EventArgs e)
{
ImageAnimator.StopAnimate(bitmap, new EventHandler(this.OnFrameChanged)); //停止播放GIF动画
}