搜尋此網誌

載入中…

2008年11月24日 星期一

C# 利用SaveFileDialog儲存pictureBox1圖片於自設路徑


private void button1_Click(object sender, EventArgs e)
{
try
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Bitmap Image|*.bmp";
saveFileDialog1.Title = "儲存圖片";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName != "")
{
System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();

switch (saveFileDialog1.FilterIndex)
{
case 1:
this.pictureBox1.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Bmp);
break;
}

fs.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

1 則留言: