用Drawing.Image.Save保存图片时如何设置品质? 如JPEG,直接生成的品质很差。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 应该是在[C#]public void Save( string filename, ImageCodecInfo encoder, EncoderParameters encoderParams);encoder和encoderParams上做文章,我也是学习:) 确实如此,品质很差.关注ing.. 印象中有一个属性是设置图片的质量,但是具体我也网了,保存的方式重载几次,但好象都没有设置质量的,你还是查查MSDN /// <summary>/// 不失真获得缩微图/// </summary>/// <returns></returns>public bool GetThumbImg(){ try { string imgpath;//原始路径 if(imgsourceurl.IndexOf("\\",0)<0)//使用的是相对路径 { imgpath=HttpContext.Current.Server.MapPath(imgsourceurl);//转化为物理路径 } else { imgpath=imgsourceurl; } System.Drawing.Image sourceImage = System.Drawing.Image.FromFile(imgpath); int width = sourceImage.Width; int height = sourceImage.Height; if(thumbwidth<=0) { thumbwidth=120; } if(thumbwidth>=width) { return false; } else {//关键在这里: Image imgThumb=new System.Drawing.Bitmap(thumbwidth,height*thumbwidth/width); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(imgThumb); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(sourceImage, new Rectangle(0, 0, thumbwidth,height*thumbwidth/width), 0, 0, width, height, GraphicsUnit.Pixel); string thumbpath=""; sourceImage.Dispose(); //myBitmap.Dispose(); if(thumburl=="") { //File.Delete(HttpContext.Current.Server.MapPath(imgpath)); thumbpath=imgpath; } if(thumbpath.IndexOf("\\",0)<0)//使用的是相对路径 { thumbpath=HttpContext.Current.Server.MapPath(thumburl);//转化为物理路径 } imgThumb.Save(thumbpath,ImageFormat.Jpeg); imgThumb.Dispose(); return true; } } catch { throw; }} DropDownList 修改时如何取得值。 asp.net 导出文件 弹出保存路径对话框 求一正则判断年份是否输入正确 未将对象引用设置到对象的实例。 在asp.net 页面代码中如何循环显示数据库中数据(不用任何控件),具体怎么写??? 执行vbs文件时的异常处理 高分求字符串比较的算法 一个帐号只能在一台特定的机器上使用,在其它的机器上不能使用这个帐号登录网站,请问怎样做比较好? 问一个对大虾们来说是超简单的问题。。。! 还有一个问题~,也是关于有效性验证的!! 200分求可上载的FTP空间. 在OnLoad中限制图片大小的问题,只有第一次和以后刷新才有效!
[C#]
public void Save(
string filename,
ImageCodecInfo encoder,
EncoderParameters encoderParams
);encoder和encoderParams上做文章,我也是学习:)
/// 不失真获得缩微图
/// </summary>
/// <returns></returns>
public bool GetThumbImg()
{
try
{
string imgpath;//原始路径
if(imgsourceurl.IndexOf("\\",0)<0)//使用的是相对路径
{
imgpath=HttpContext.Current.Server.MapPath(imgsourceurl);//转化为物理路径
}
else
{
imgpath=imgsourceurl;
}
System.Drawing.Image sourceImage = System.Drawing.Image.FromFile(imgpath);
int width = sourceImage.Width;
int height = sourceImage.Height;
if(thumbwidth<=0)
{
thumbwidth=120;
}
if(thumbwidth>=width)
{
return false;
}
else
{
//关键在这里:
Image imgThumb=new System.Drawing.Bitmap(thumbwidth,height*thumbwidth/width);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(imgThumb);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(sourceImage, new Rectangle(0, 0, thumbwidth,height*thumbwidth/width), 0, 0, width, height, GraphicsUnit.Pixel);
string thumbpath="";
sourceImage.Dispose();
//myBitmap.Dispose();
if(thumburl=="")
{
//File.Delete(HttpContext.Current.Server.MapPath(imgpath));
thumbpath=imgpath;
}
if(thumbpath.IndexOf("\\",0)<0)//使用的是相对路径
{
thumbpath=HttpContext.Current.Server.MapPath(thumburl);//转化为物理路径
}
imgThumb.Save(thumbpath,ImageFormat.Jpeg);
imgThumb.Dispose();
return true;
}
}
catch
{
throw;
}
}