C# 未处理访问冲突异常
我正试图通过打印页面上的C# 未处理访问冲突异常,c#,winforms,image,printing,C#,Winforms,Image,Printing,我正试图通过打印页面上的事件打印图像,如下所示 protected virtual void OnPrintPage(object sender, PrintPageEventArgs e) { Image img = ExportAsMetafile(0); CultureInfo current = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInf
事件打印图像,如下所示
protected virtual void OnPrintPage(object sender, PrintPageEventArgs e)
{
Image img = ExportAsMetafile(0);
CultureInfo current = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
e.Graphics.DrawImage(img, new Rectangle(0, 0, (int)e.Graphics.VisibleClipBounds.Width, (int)e.Graphics.VisibleClipBounds.Height));
Thread.CurrentThread.CurrentCulture = current;
}
当我试图通过img.Save(“img.png”)保存img时代码>,我得到了我需要的图像
但是,当我尝试在e.Graphics.DrawImage
中绘制此图像时,它显示以下异常
有人能帮我解决这个问题吗?你为什么不试试这个(注意我是从msdn得到的)
如果您指定了目标文件的完整路径,该怎么办?对不起,我找不到您。。trippino如果您使用类似这样的东西会怎么样:img.Save(“D:\\img.png”)代码>?这不是问题,伙计。。。。只是为了测试,我做了。。。。它正确地保存了图像。。。。但是我不会画图。。这就是你的图像使打印机驱动程序崩溃的原因,可能是因为你画的太大了。你需要找一个更好的。
e.Graphics.DrawImage(Image.FromFile("C:\\My Folder\\MyFile.bmp"), ev.Graphics.VisibleClipBounds);