直接从EXE文件运行时,SaveFileDialog无法正常工作 [英] SaveFileDialog not working when it is being run directly from the EXE file
本文介绍了直接从EXE文件运行时,SaveFileDialog无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用C#制作加菲猫漫画浏览器。我有一个按钮,可以将屏幕上的漫画保存到计算机上。但是,当我从Visual C#Express编译它时,它可以完美地保存。当我从目录运行exe文件时,我收到一条未处理的异常消息,指出GDI +中发生了一般错误。这是我的保存代码:
I am making a Garfield comic viewer in C#. I have a button that saves the comic on screen to the computer. However, when I compile it from Visual C# Express, it saves perfectly. When I run the exe file from the directory, I get an unhandled exception message stating "A generic error occurred in GDI+". Here is my saving code:
private void save_Click(object sender, EventArgs e)
{
using (SaveFileDialog dialog = new SaveFileDialog())
{
dialog.Title = "Save Dialog";
dialog.Filter = "Bitmap Images (*.bmp)|*.bmp|All files(*.*)|*.*";
if (dialog.ShowDialog(this) == DialogResult.OK)
{
using (Bitmap bmp = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height))
{
pictureBox1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
pictureBox1.Image = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height);
pictureBox1.Image.Save("c://cc.Jpg");
bmp.Save(dialog.FileName);
pictureBox1.ImageLocation = "http://garfield.com/uploads/strips" + "/" + whole.ToString("yyyy-MM-dd") + ".jpg";
MessageBox.Show("Comic Saved.");
}
}
}
}
我该怎么办?
What can I do?
推荐答案
Win7上的C:的根目录只读给非管理员。试图创建一个文件会失败。
另外,为什么在这个地球上你在PictureBox上调用DrawToBitmap?它已经显示了一个位图,所以绝对没有理由这样做!
The root of C: on Win7 is readonly to non-Admins. Trying to create a file there will fail.
Also, WHY on this earth are you calling DrawToBitmap on the PictureBox?? It's already showing a Bitmap, so there's absolutely no reason to do this!
这篇关于直接从EXE文件运行时,SaveFileDialog无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文