private void ReSizeImg(string absPath,int width,int height)
{
if (absPath.ToLower().IndexOf(".gif")<0)
{
Image oldImg = Image.FromFile(absPath);
if (oldImg.Width > width || oldImg.Height > height)
{
int _w, _h;
float _b = width / height;
float _b2 = oldImg.Width / oldImg.Height;
if (_b2 > _b)
{
_h = height;
_w = Convert.ToInt32(oldImg.Width / (oldImg.Height / _h));
}
else
{
_w = width;
_h = Convert.ToInt32(oldImg.Height/(oldImg.Width/_w));
}
Image newImg = oldImg.GetThumbnailImage(_w, _h, null, IntPtr.Zero);
newImg.Save(absPath);
newImg.Dispose();
}
oldImg.Dispose();
}
}
未处理的异常: System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般
性错误。
在 System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, Encoder
Parameters encoderParams)
在 System.Drawing.Image.Save(String filename, ImageFormat format)
在 System.Drawing.Image.Save(String filename)
在 ReSize.Program.ReSizeImg(String absPath, Int32 width, Int32 height)
在 ReSize.Program.Execute()
在 ReSize.Program.Main(String[] args)
你保存的时候换一个文件名称试一试!