【发布时间】:2015-11-05 00:39:12
【问题描述】:
我创建了一个分形绘图程序,并尝试在其中加入一个按钮来保存当前位图。我使用 mandelbrot() 方法,但按钮和代码似乎不起作用,它只是抛出错误。这是绘制和保存位图的代码:
我以为是文件夹权限的原因,所以我添加了代码将其保存到当前用户的桌面。但还是同样的错误。
绘制位图
private Bitmap picture;
private Graphics g1;
private void Form1_Paint(object sender, PaintEventArgs e)
{
//put the bitmap on the window
Graphics windowG = e.Graphics;
windowG.DrawImageUnscaled(picture, 0, 0);
}
保存位图
private void savefractal_Click(object sender, EventArgs e)
{
try
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
picture.Save(path);
savefractal.Text = "Saved file.";
}
catch (Exception)
{
MessageBox.Show("There was a problem saving the file." +
" Check the file permissions.");
}
}
【问题讨论】: