/// <summary>
/// 无损压缩图片
/// </summary>
/// <param name="sFile">原图片</param>
/// <returns></returns>
public bool GetPicThumbnail(string sFile)
{
System.Drawing.Image iSource = System.Drawing.Image.FromFile(sFile);
MemoryStream ms = new MemoryStream();
iSource.Save(ms, iSource.RawFormat);
System.Drawing.Image iSource0 = System.Drawing.Image.FromStream(ms);
try
{
iSource.Dispose();
File.Delete(sFile);
iSource0.Save(sFile);//dFile是压缩后的新路径
return true;
}
catch
{
return false;
}
finally
{
//iSource.Dispose();
ms.Close();
iSource0.Dispose();
}
}
图片原图复制自己 解决图片上传不完整,图片打不开
最新推荐文章于 2022-04-19 16:35:50 发布