失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > php 缩略图不失真 c#生成缩略图不失真的方法实例分享

php 缩略图不失真 c#生成缩略图不失真的方法实例分享

时间:2020-07-08 23:40:39

相关推荐

php 缩略图不失真 c#生成缩略图不失真的方法实例分享

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 <= 0)

{

thumbwidth = 120;

}

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中文网()!

发布php中文网,转载请注明出处,感谢您的尊重!

如果觉得《php 缩略图不失真 c#生成缩略图不失真的方法实例分享》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。