欢迎来到天天文库
浏览记录
ID:59256016
大小:16.50 KB
页数:2页
时间:2020-09-08
《c图片按比例缩放.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、publicstaticBitmapGetThumbnail(Bitmapb,intdestHeight,intdestWidth) { System.Drawing.ImageimgSource=b; System.Drawing.Imaging.ImageFormatthisFormat=imgSource.RawFormat; intsW=0,sH=0;
2、 //按比例缩放 intsWidth=imgSource.Width; intsHeight=imgSource.Height; if(sHeight>destHeight
3、
4、sWidth>destWidth) { if((sWidth*destHeight)>(sHeight*destWidth)) {
5、 sW=destWidth; sH=(destWidth*sHeight)/sWidth; } else { sH=destHeight; sW=(sWidth*d
6、estHeight)/sHeight; } } else { sW=sWidth; sH=sHeight; } BitmapoutBmp=newBitmap(destWidth,destHeight);
7、 Graphicsg=Graphics.FromImage(outBmp); g.Clear(Color.Transparent); //设置画布的描绘质量 g.CompositingQuality=CompositingQuality.HighQuality; g.SmoothingMode=SmoothingMode.HighQuality; g
8、.InterpolationMode=InterpolationMode.HighQualityBicubic; g.DrawImage(imgSource,newRectangle((destWidth-sW)/2,(destHeight-sH)/2,sW,sH),0,0,imgSource.Width,imgSource.Height,GraphicsUnit.Pixel); g.Dispose(); //以下代码为保
9、存图片时,设置压缩质量 EncoderParametersencoderParams=newEncoderParameters(); long[]quality=newlong[1]; quality[0]=100; EncoderParameterencoderParam=newEncoderParameter(System.Drawing.Imaging.Encoder.Quality,qu
10、ality); encoderParams.Param[0]=encoderParam; imgSource.Dispose(); returnoutBmp; }
此文档下载收益归作者所有