我有一个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; }
原文地址:https://www.jb51.cc/aspnet/254599.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。