c#中将pictureBox中的图片保存到本地中
·
c#中将pictureBox中的图片保存到本地中
this.pictureBox.Image.Save("D://你好.jpg");
上面这种方式指定了路径和名称,需要将路径和名称参数化
下面这种方式就更加的灵活
SaveFileDialog saveImageDialog = new SaveFileDialog();
saveImageDialog.Title = "图片保存";
saveImageDialog.Filter = @"jpeg|*.jpg|png|*.png";
//设置默认文件名(可以不设置)
saveImageDialog.FileName = "对比曲线图";
//主设置默认文件extension(可以不设置)
saveImageDialog.DefaultExt = "jpg";
if (saveImageDialog.ShowDialog() == DialogResult.OK)
{
string fileName = saveImageDialog.FileName.ToString();
if (fileName != "" && fileName != null)
{
string fileExtName = fileName.Substring(fileName.LastIndexOf(".") + 1).ToString();
System.Drawing.Imaging.ImageFormat imgformat = null;
if (fileExtName != "")
{
switch (fileExtName)
{
case "jpg":
imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
case "png":
imgformat = System.Drawing.Imaging.ImageFormat.Png;
break;
default:
imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
}
try
{
Bitmap bit = new Bitmap(pictureBox.Image);
MessageBox.Show("保存路径:" + fileName, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
pictureBox.Image.Save(fileName, imgformat);
}
catch
{
}
}
}
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)