欢迎访问 生活随笔!

尊龙游戏旗舰厅官网

当前位置: 尊龙游戏旗舰厅官网 > 编程语言 > asp.net >内容正文

asp.net

asp.net上传图片文件自动修改图片大小代码 -尊龙游戏旗舰厅官网

发布时间:2025/1/21 asp.net 17 豆豆
尊龙游戏旗舰厅官网 收集整理的这篇文章主要介绍了 asp.net上传图片文件自动修改图片大小代码 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
#region 图片缩放/// /// 图片缩放/// /// 图片相对路径/// 图片名称/// 缩放宽度/// 高度/// 1--固定缩放;2--按比例缩放;3--指定宽度,宽度大于指定宽度按指定宽度进行等比缩放,小于指定宽度按原图大小上传;4--原图直接上传/// public static void reducespic(string savepath,string filename, int destwidth, int destheight, int type){if (!filename.equals("")){string allpath = system.web.httpcontext.current.server.mappath("/") savepath;//生成原图 system.io.stream stream = system.io.file.openread(allpath filename);system.drawing.image oimage = system.drawing.image.fromstream(stream);stream.close();stream.dispose();system.drawing.image.getthumbnailimageabort callb = new system.drawing.image.getthumbnailimageabort(thumbnailcallback);string filetype = filename.substring(filename.lastindexof(".") 1);int owidth = oimage.width;int oheight = oimage.height;int twidth = destwidth; //设置缩略图初始宽度 int theight = destheight; //设置缩略图初始高度//按指定宽高缩放if (type == 1){twidth = destwidth;theight = destheight;}//按比例计算出缩略图的宽度和高度 else if (type == 2){if (owidth > twidth || oheight > theight){if (owidth >= oheight){theight = (int)math.floor(convert.todouble(oheight) * (convert.todouble(twidth) / convert.todouble(owidth)));}else{twidth = (int)math.floor(convert.todouble(owidth) * (convert.todouble(theight) / convert.todouble(oheight)));}}else{twidth = owidth; //原图宽度 theight = oheight; //原图高度}}//指定宽度,宽度大于指定宽度按指定宽度进行等比缩放,小于指定宽度按原图大小上传else if (type == 3){if (owidth >= twidth){if (owidth >= oheight){theight = (int)math.floor(convert.todouble(oheight) * (convert.todouble(twidth) / convert.todouble(owidth)));}else{twidth = (int)math.floor(convert.todouble(owidth) * (convert.todouble(theight) / convert.todouble(oheight)));}}else{twidth = owidth; //原图宽度 theight = oheight; //原图高度}}else{twidth = owidth; //原图宽度 theight = oheight; //原图高度}//生成缩略原图 oimage = oimage.getthumbnailimage(twidth, theight, callb, intptr.zero);oimage.save(allpath filename);}}public static bool thumbnailcallback() { return false; }#endregion

转载于:https://www.cnblogs.com/fogwang/p/3930831.html

总结

以上是尊龙游戏旗舰厅官网为你收集整理的asp.net上传图片文件自动修改图片大小代码的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得尊龙游戏旗舰厅官网网站内容还不错,欢迎将尊龙游戏旗舰厅官网推荐给好友。

网站地图