ASP.NET图像上传与调整大小
发布时间:2020-12-15 19:13:59 所属栏目:asp.Net 来源:网络整理
导读:我有一个aspx页面,将上传图像到服务器硬盘从客户端pc 但现在我需要改变我的程序,这将允许我在上传时调整图像的大
我有一个aspx页面,将上传图像到服务器硬盘从客户端pc
但现在我需要改变我的程序,这将允许我在上传时调整图像的大小。 有人有任何想法吗?我不能找到这些属性/方法与输入文件服务器控制 任何一个有指导我? 解决方法
一旦文件已保存到服务器,您可以使用这样的代码来调整大小。这个代码将在调整大小时处理长宽比。
public static Bitmap CreateThumbnail(string lcFilename,int lnWidth,int lnHeight) { System.Drawing.Bitmap bmpOut = null; try { Bitmap loBMP = new Bitmap(lcFilename); ImageFormat loFormat = loBMP.RawFormat; decimal lnRatio; int lnNewWidth = 0; int lnNewHeight = 0; if (loBMP.Width < lnWidth && loBMP.Height < lnHeight) return loBMP; if (loBMP.Width > loBMP.Height) { lnRatio = (decimal)lnWidth / loBMP.Width; lnNewWidth = lnWidth; decimal lnTemp = loBMP.Height * lnRatio; lnNewHeight = (int)lnTemp; } else { lnRatio = (decimal)lnHeight / loBMP.Height; lnNewHeight = lnHeight; decimal lnTemp = loBMP.Width * lnRatio; lnNewWidth = (int)lnTemp; } bmpOut = new Bitmap(lnNewWidth,lnNewHeight); Graphics g = Graphics.FromImage(bmpOut); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; g.FillRectangle(Brushes.White,lnNewWidth,lnNewHeight); g.DrawImage(loBMP,lnNewHeight); loBMP.Dispose(); } catch { return null; } return bmpOut; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-4 – 使asp.net MVC 4视图编译/给出编译错误,而
- asp.net-mvc – 为什么我不能从Web平台安装程序安装ASPNET
- 在ASP.NET中生成新的SessionId
- asp.net-mvc – jQuery Mobile和不显眼的验证
- .Net Core微服务入门全纪录(八)——Docker Compose与容器
- 用asp.net core 2.0 + EFCore.Sqlite做个小网站
- asp.net – Web部署:如何将文件保存在特定目标文件夹中
- asp.net-mvc-4 – Azure云服务将http重定向到https无效(在许
- ASP.NET MVC3 RC2从请求参数绑定到方法参数的bug
- asp.net-mvc – EF6模型和WebAPI 2.2 OData 4.0模型如何相关