怎么把PICTUREBOX里的图片保存到本地?C#
privatevoidbutton1_Click(objectsender,EventArgse)//保存图片{saveFileDialog1.Filter="JPegI...
private void button1_Click(object sender, EventArgs e)//保存图片
{
saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif|PNG Image|*.png";
saveFileDialog1.Title = "Save";
saveFileDialog1.FileName = string.Empty;
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.Jpeg);
break;
case 2:
this.pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
break;
case 3:
this.pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Gif);
break;
case 4:
this.pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
break;
}
fs.Close();
}
}
如题?
这个代码是将生成的图片显示在pictruebox里,但是我现在想把这个图片保存到本地。但是pictruebox是不能直接保存下来的,请问有什么方法能将pictruebox里的内容附给Image image里,再来保存? 展开
{
saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif|PNG Image|*.png";
saveFileDialog1.Title = "Save";
saveFileDialog1.FileName = string.Empty;
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.Jpeg);
break;
case 2:
this.pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
break;
case 3:
this.pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Gif);
break;
case 4:
this.pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
break;
}
fs.Close();
}
}
如题?
这个代码是将生成的图片显示在pictruebox里,但是我现在想把这个图片保存到本地。但是pictruebox是不能直接保存下来的,请问有什么方法能将pictruebox里的内容附给Image image里,再来保存? 展开
1个回答
展开全部
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Image files (*.jpg)|*.jpg";
saveFileDialog.FilterIndex = 0;
saveFileDialog.RestoreDirectory = true;
saveFileDialog.Title = "导出文件保存路径";
saveFileDialog.FileName = null;
saveFileDialog.ShowDialog();
string strPath = saveFileDialog.FileName;
Image img = pictureBox1.Image;
img.Save(strPath);
saveFileDialog.Filter = "Image files (*.jpg)|*.jpg";
saveFileDialog.FilterIndex = 0;
saveFileDialog.RestoreDirectory = true;
saveFileDialog.Title = "导出文件保存路径";
saveFileDialog.FileName = null;
saveFileDialog.ShowDialog();
string strPath = saveFileDialog.FileName;
Image img = pictureBox1.Image;
img.Save(strPath);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询