C#的WinForms画为位图参数无效 [英] C# winforms draw to bitmap invalid parameter

查看:113
本文介绍了C#的WinForms画为位图参数无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经提出了申请,而我需要的功能drawbitmap打印我的面板。当我按下按钮(btnUpdate)的12倍以上我得到这个规则的一个参数(无效参数): panel1.DrawToBitmap(BMP1,新的Rectangle(0,0,2480,3508));

I have made an application, and i need the function drawbitmap to print my panel. When i push the button (btnUpdate) 12 times or more I get a parameter exception(invalid parameter)on this rule: panel1.DrawToBitmap(bmp1, new Rectangle(0, 0, 2480, 3508));

private void preview()
        {
            Bitmap bmp1 = new Bitmap(2480, 3508);
            panel1.DrawToBitmap(bmp1, new Rectangle(0, 0, 2480, 3508));
            pictureBox2.Image = bmp1;
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            preview();
        }

有人能帮助我吗?

Can someone help me please?

我不能使用 bmp1.Dispose(); 函数...我得到这一行Program.cs文件的exeption: Application.Run(新Form1的());

I can't use the bmp1.Dispose(); function... I get an exeption in the Program.cs file in this line: Application.Run(new Form1());

推荐答案

该问题是由这样的固定:

The problem is fixed by doing this:

private void preview()
{

    Bitmap bmp1 = new Bitmap(2480, 3508);
    panel1.DrawToBitmap(bmp1, new Rectangle(0, 0, 2480, 3508));
    Image img = pictureBox2.Image;
    pictureBox2.Image = bmp1;
    if (img != null) img.Dispose(); // the first time it'll be null

}

private void btnUpdate_Click(object sender, EventArgs e)
{
    preview();
    System.GC.Collect();
    System.GC.WaitForPendingFinalizers();
}

这篇关于C#的WinForms画为位图参数无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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