首页 新闻 会员 周边

System.Drawing.Image.Save 我这个代码有错么?为何总报错

0
悬赏园豆:30 [已关闭问题] 关闭于 2012-01-03 10:47
        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)

fun5的主页 fun5 | 初学一级 | 园豆:4
提问于:2011-10-28 17:09
< >
分享
所有回答(1)
-1

你保存的时候换一个文件名称试一试!

小小刀 | 园豆:1991 (小虾三级) | 2011-10-29 09:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册