private void SaveImg()
{
Image Img;
string pictureUrl = FunManage.ImgLogUrl();//保存图片路径
FileInfo FileUrl = new FileInfo(pictureUrl);//防止路径中有日期导致路径错误
string pictureName = System.DateTime.Now.ToString("yyyyMMdd")+".jpg";
//照片另存
//using (MemoryStream mem = new MemoryStream())
//{
// //这句很重要,不然不能正确保存图片或出错(关键就这一句)
// Bitmap bmp = new Bitmap(Img);
// //保存到磁盘文件
// //bmp.Save(@pictureUrl + pictureName, ImageFormat.Jpeg);
// Img.Dispose();
// bmp.Save(FileUrl + pictureName);
// bmp.Dispose();
//}
try
{
using (Bitmap bitmap = new Bitmap(Img))
{
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, ImageFormat.Jpeg);
Image img = Image.FromStream(stream);
//img.Save(FileUrl +"\\"+ pictureName);
//img.Dispose();
string szURL = FileUrl + "\\" + pictureName;
img.Save(szURL, ImageFormat.Jpeg);
img.Dispose();
}
}
}
catch (Exception)
{
if (Img != null)
{
Img.Dispose();
}
}
}