public void MakeSmallImg(System.Web.HttpPostedFile postFile,string saveImg,System.Double Width,System.Double Height)
{
//原始图片名称
string originalFilename = postFile.FileName;
//生成的高质量图片名称
string strGoodFile = saveImg;
//从文件取得图片对象
System.Drawing.Image image= System.Drawing.Image.FromStream(postFile.InputStream,true);
System.Double NewWidth,NewHeight;
if(image.Width>image.Height)
{
NewWidth=Width;
NewHeight=image.Height*(NewWidth/image.Width);
}
else
{
NewHeight=Height;
NewWidth=(NewHeight/image.Height)*image.Width;
}
if (NewWidth>Width)
{
NewWidth=Width;
}
if (NewHeight>Height)
{
NewHeight=Height;
}
System.Drawing.Size size;
System.Drawing.Image bitmap=null;
System.Drawing.Graphics g=null; try
{
//取得图片大小
size = new Size((int)NewWidth,(int)NewHeight); }
catch
{
throw new ArgumentException("1");
}
try
{
//新建一个bmp图片
bitmap = new System.Drawing.Bitmap(size.Width,size.Height);
}
catch
{
throw new ArgumentException("2");
}
try
{
//新建一个画板
g = System.Drawing.Graphics.FromImage(bitmap);
}
catch
{
throw new ArgumentException("3");
}
try
{
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
}
catch
{
throw new ArgumentException("4");
}
try
{
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
}
catch
{
throw new ArgumentException("5");
}
//清空一下画布
g.Clear(Color.White);
try
{
//在指定位置画图
g.DrawImage(image,new System.Drawing.Rectangle(0,0,bitmap.Width,bitmap.Height)
, new System.Drawing.Rectangle(0,0,image.Width,image.Height),System.Drawing.GraphicsUnit.Pixel);
}
catch
{
throw new ArgumentException("6");
}
//保存高清晰度的缩略图
bitmap.Save(strGoodFile,System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
bitmap.Dispose();
}如果上传的图片宽度像素大于3000PX时,就会服务器就会报 “内存不足”,但如果小于2500就可以。。请问如何解决??? 盼复
{
//原始图片名称
string originalFilename = postFile.FileName;
//生成的高质量图片名称
string strGoodFile = saveImg;
//从文件取得图片对象
System.Drawing.Image image= System.Drawing.Image.FromStream(postFile.InputStream,true);
System.Double NewWidth,NewHeight;
if(image.Width>image.Height)
{
NewWidth=Width;
NewHeight=image.Height*(NewWidth/image.Width);
}
else
{
NewHeight=Height;
NewWidth=(NewHeight/image.Height)*image.Width;
}
if (NewWidth>Width)
{
NewWidth=Width;
}
if (NewHeight>Height)
{
NewHeight=Height;
}
System.Drawing.Size size;
System.Drawing.Image bitmap=null;
System.Drawing.Graphics g=null; try
{
//取得图片大小
size = new Size((int)NewWidth,(int)NewHeight); }
catch
{
throw new ArgumentException("1");
}
try
{
//新建一个bmp图片
bitmap = new System.Drawing.Bitmap(size.Width,size.Height);
}
catch
{
throw new ArgumentException("2");
}
try
{
//新建一个画板
g = System.Drawing.Graphics.FromImage(bitmap);
}
catch
{
throw new ArgumentException("3");
}
try
{
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
}
catch
{
throw new ArgumentException("4");
}
try
{
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
}
catch
{
throw new ArgumentException("5");
}
//清空一下画布
g.Clear(Color.White);
try
{
//在指定位置画图
g.DrawImage(image,new System.Drawing.Rectangle(0,0,bitmap.Width,bitmap.Height)
, new System.Drawing.Rectangle(0,0,image.Width,image.Height),System.Drawing.GraphicsUnit.Pixel);
}
catch
{
throw new ArgumentException("6");
}
//保存高清晰度的缩略图
bitmap.Save(strGoodFile,System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
bitmap.Dispose();
}如果上传的图片宽度像素大于3000PX时,就会服务器就会报 “内存不足”,但如果小于2500就可以。。请问如何解决??? 盼复
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货