问题描述
最近在忙大作业,,要求做一个图片浏览器,可是在图片的缩放不懂
解决方案
解决方案二:
http://www.baidu.com/s?bs=c%23+%CD%BC%C6%AC%B4%A6%C0%ED&f=8&rsv_bp=1&rsv_spt=3&wd=c%23+%CD%BC%C6%AC%CB%F5%B7%C5&inputT=2135
解决方案三:
#region正方型裁剪并缩放///<summary>///正方型裁剪///以图片中心为轴心,截取正方型,然后等比缩放///用于头像处理///</summary>///<remarks>吴剑2010-11-23</remarks>///<paramname="postedFile">原图HttpPostedFile对象</param>///<paramname="fileSaveUrl">缩略图存放地址</param>///<paramname="side">指定的边长(正方型)</param>///<paramname="quality">质量(范围0-100)</param>publicstaticvoidCutForSquare(System.Web.HttpPostedFilepostedFile,stringfileSaveUrl,intside,intquality){//创建目录stringdir=Path.GetDirectoryName(fileSaveUrl);if(!Directory.Exists(dir))Directory.CreateDirectory(dir);//原始图片(获取原始图片创建对象,并使用流中嵌入的颜色管理信息)System.Drawing.ImageinitImage=System.Drawing.Image.FromStream(postedFile.InputStream,true);//原图宽高均小于模版,不作处理,直接保存if(initImage.Width<=side&&initImage.Height<=side){initImage.Save(fileSaveUrl,System.Drawing.Imaging.ImageFormat.Jpeg);}else{//原始图片的宽、高intinitWidth=initImage.Width;intinitHeight=initImage.Height;//非正方型先裁剪为正方型if(initWidth!=initHeight){//截图对象System.Drawing.ImagepickedImage=null;System.Drawing.GraphicspickedG=null;//宽大于高的横图if(initWidth>initHeight){//对象实例化pickedImage=newSystem.Drawing.Bitmap(initHeight,initHeight);pickedG=System.Drawing.Graphics.FromImage(pickedImage);//设置质量pickedG.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;pickedG.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;//定位RectanglefromR=newRectangle((initWidth-initHeight)/2,0,initHeight,initHeight);RectangletoR=newRectangle(0,0,initHeight,initHeight);//画图pickedG.DrawImage(initImage,toR,fromR,System.Drawing.GraphicsUnit.Pixel);//重置宽initWidth=initHeight;}//高大于宽的竖图else{//对象实例化pickedImage=newSystem.Drawing.Bitmap(initWidth,initWidth);pickedG=System.Drawing.Graphics.FromImage(pickedImage);//设置质量pickedG.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;pickedG.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;//定位RectanglefromR=newRectangle(0,(initHeight-initWidth)/2,initWidth,initWidth);RectangletoR=newRectangle(0,0,initWidth,initWidth);//画图pickedG.DrawImage(initImage,toR,fromR,System.Drawing.GraphicsUnit.Pixel);//重置高initHeight=initWidth;}//将截图对象赋给原图initImage=(System.Drawing.Image)pickedImage.Clone();//释放截图资源pickedG.Dispose();pickedImage.Dispose();}//缩略图对象System.Drawing.ImageresultImage=newSystem.Drawing.Bitmap(side,side);System.Drawing.GraphicsresultG=System.Drawing.Graphics.FromImage(resultImage);//设置质量resultG.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;resultG.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;//用指定背景色清空画布resultG.Clear(Color.White);//绘制缩略图resultG.DrawImage(initImage,newSystem.Drawing.Rectangle(0,0,side,side),newSystem.Drawing.Rectangle(0,0,initWidth,initHeight),System.Drawing.GraphicsUnit.Pixel);//关键质量控制//获取系统编码类型数组,包含了jpeg,bmp,png,gif,tiffImageCodecInfo[]icis=ImageCodecInfo.GetImageEncoders();ImageCodecInfoici=null;foreach(ImageCodecInfoiinicis){if(i.MimeType=="image/jpeg"||i.MimeType=="image/bmp"||i.MimeType=="image/png"||i.MimeType=="image/gif"){ici=i;}}EncoderParametersep=newEncoderParameters(1);ep.Param[0]=newEncoderParameter(System.Drawing.Imaging.Encoder.Quality,(long)quality);//保存缩略图resultImage.Save(fileSaveUrl,ici,ep);//释放关键质量控制所用资源ep.Dispose();//释放缩略图资源resultG.Dispose();resultImage.Dispose();//释放原始图片资源initImage.Dispose();}}
解决方案四:
谢谢啦,虽然不知道用不用上
解决方案五:
收藏一下,以后会有用处,谢谢楼主发贴!