ASP.NET图像上传与调整大小

我有一个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;
}

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....