c#生成缩略图不失真的方法实例分享
////// 获得缩微图/// /// 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 = width){return false;}else{(thumbwidth,thHeight*thumbwidth/thWidth,null,IntPtr.Zero);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();if(thumburl==""){thumbpath=imgpath;}if(thumbpath.IndexOf("\",0)<0)//使用的是相对路径 {thumbpath=HttpContext.Current.Server.MapPath(thumburl);//转化为物理路径 }imgThumb.Save(thumbpath,ImageFormat.Jpeg);imgThumb.Dispose();return true;}}catch{throw;}}
以上就是c#生成缩略图不失真的方法实例分享的内容,更多相关内容请关注PHP中文网(www.php.cn)!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1431944.html
微信扫一扫
支付宝扫一扫