我们孩还发多夫道知道了,就得看不我们后心回的 "家 ",不是起用看把一个有邮递区号邮差找得到的家,后心天能们后心回的 "家 ",不是空于而,风每都到小是一段时光。
privateSizeNewSize(intmaxWidth,intmaxHeight,intwidth,intheight) {
doublew=0.0;
doubleh=0.0;
doublesw=Convert.ToDouble(width);
doublesh=Convert.ToDouble(height);
doublemw=Convert.ToDouble(maxWidth);
doublemh=Convert.ToDouble(maxHeight); if(sw<mw&&sh<mh)
{
w=sw;
h=sh;
}
elseif((sw/sh)>(mw/mh))
{
w=maxWidth;
h=(w*sh)/sw;
}
else
{
h=maxHeight;
w=(h*sw)/sh;
} returnnewSize(Convert.ToInt32(w),Convert.ToInt32(h));
} privatevoidSendSmallImage(stringfileName,intmaxWidth,intmaxHeight)
{
System.Drawing.Imageimg=System.Drawing.Image.FromFile(Server.MapPath(fileName));
System.Drawing.Imaging.ImageFormatthisFormat=img.RawFormat; SizenewSize=NewSize(maxWidth,maxHeight,img.Width,img.Height);
BitmapoutBmp=newBitmap(newSize.Width,newSize.Height);
Graphicsg=Graphics.FromImage(outBmp); //设置画布的描绘质量
g.CompositingQuality=CompositingQuality.HighQuality;
g.SmoothingMode=SmoothingMode.HighQuality;
g.InterpolationMode=InterpolationMode.HighQualityBicubic; g.DrawImage(img,newRectangle(0,0,newSize.Width,newSize.Height),
0,0,img.Width,img.Height,GraphicsUnit.Pixel);
g.Dispose(); if(thisFormat.Equals(ImageFormat.Gif))
{
Response.ContentType="image/gif";
}
else
{
Response.ContentType="image/jpeg";
} //以下代码为保存图片时,设置压缩质量
EncoderParametersencoderParams=newEncoderParameters();
long[]quality=newlong[1];
quality[0]=100; EncoderParameterencoderParam=newEncoderParameter(System.Drawing.Imaging.Encoder.Quality,quality);
encoderParams.Param[0]=encoderParam; //获得包含有关内置图像编码解码器的信息的ImageCodecInfo对象。
ImageCodecInfo[]arrayICI=ImageCodecInfo.GetImageEncoders();
ImageCodecInfojpegICI=null;
for(intx=0;x<arrayICI.Length;x++)
{
if(arrayICI[x].FormatDescription.Equals("JPEG"))
{
jpegICI=arrayICI[x];//设置JPEG编码
break;
}
} if(jpegICI!=null)
{
outBmp.Save(Response.OutputStream,jpegICI,encoderParams);
}
else
{
outBmp.Save(Response.OutputStream,thisFormat);
} img.Dispose();
outBmp.Dispose();
}
本文ASP.NET中高质量缩略图的生成代码到此结束。永远别放下自我,哪怕所有人都放下了你。小编再次感谢大家对我们的支持!