c图片按比例缩放

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

publicstaticBitmapGetThumbnail(Bitmapb,intdestHeight,intdestWidth){System.Drawing.ImageimgSource=b;System.Drawing.Imaging.ImageFormatthisFormat=imgSource.RawFormat;intsW=0,sH=0;//按比例缩放intsWidth=imgSource.Width;intsHeight=imgSource.Height;if(sHeightdestHeight||sWidthdestWidth){if((sWidth*destHeight)(sHeight*destWidth)){sW=destWidth;sH=(destWidth*sHeight)/sWidth;}else{sH=destHeight;sW=(sWidth*destHeight)/sHeight;}}else{sW=sWidth;sH=sHeight;}BitmapoutBmp=newBitmap(destWidth,destHeight);Graphicsg=Graphics.FromImage(outBmp);g.Clear(Color.Transparent);//设置画布的描绘质量g.CompositingQuality=CompositingQuality.HighQuality;g.SmoothingMode=SmoothingMode.HighQuality;g.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();//以下代码为保存图片时,设置压缩质量EncoderParametersencoderParams=newEncoderParameters();long[]quality=newlong[1];quality[0]=100;EncoderParameterencoderParam=newEncoderParameter(System.Drawing.Imaging.Encoder.Quality,quality);encoderParams.Param[0]=encoderParam;imgSource.Dispose();returnoutBmp;}

1 / 2
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功