请问一下C#的savedialog怎么保存图片呢?
我从网上参考了一下,保存到最后发现是个无效图片,谢谢privatevoidtoolStripButton11_Click(objectsender,EventArgse)...
我从网上参考了一下,保存到最后发现是个无效图片,谢谢
private void toolStripButton11_Click(object sender, EventArgs e)
{
string localFilPath, fileNameExt;
saveFileDialog1.Filter = "图片文件(*.jpg)|*.jpg";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true;
string strPath = saveFileDialog1.FileName;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (saveFileDialog1.FileName != "")
{
localFilPath = saveFileDialog1.FileName.ToString();
fileNameExt = localFilPath.Substring(localFilPath.LastIndexOf("\\") + 1);
System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();
SaveFile(); fs.Close();
}
}
}
public void SaveFile()
{ Image im = this.pictureBox1.Image;
Bitmap bit = new Bitmap(im);
bit.Save(Application.StartupPath + "\\hah.jpg",
System.Drawing.Imaging.ImageFormat.Bmp);
} 展开
private void toolStripButton11_Click(object sender, EventArgs e)
{
string localFilPath, fileNameExt;
saveFileDialog1.Filter = "图片文件(*.jpg)|*.jpg";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true;
string strPath = saveFileDialog1.FileName;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (saveFileDialog1.FileName != "")
{
localFilPath = saveFileDialog1.FileName.ToString();
fileNameExt = localFilPath.Substring(localFilPath.LastIndexOf("\\") + 1);
System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();
SaveFile(); fs.Close();
}
}
}
public void SaveFile()
{ Image im = this.pictureBox1.Image;
Bitmap bit = new Bitmap(im);
bit.Save(Application.StartupPath + "\\hah.jpg",
System.Drawing.Imaging.ImageFormat.Bmp);
} 展开
1个回答
展开全部
bit.Save(Application.StartupPath + "\\hah.jpg", System.Drawing.Imaging.ImageFormat.Bmp);
你这图片保存路径被强制指定到跟EXE程序同一目录下的 hah.jpg 里去了,而不是
System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();
这个流所指向的地址。
追问
奥奥·~多谢指点,我那代码是抄的别人的,研究了半天没弄明白
多谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询