• asp.net修改图片的大小


    /// <summary>
    /// 修改指定图片的分辨率
    /// </summary>
    /// <param name="fileFoldUrl">文件夹url</param>
    /// <param name="fileName">文件名</param>
    /// <param name="filePath">文件路径,带文件名</param>
    /// <param name="_width">分辨率的宽</param>
    /// <param name="_height">分辨率的高</param>
    public void update_picture(string fileFoldUrl, string fileName, string filePath, int _width, int _height)
    {
        byte[] zp = this.load_pictMemory(filePath);

        MemoryStream ms = new MemoryStream(zp);

        System.Drawing.Image img = System.Drawing.Image.FromStream(ms);

        Bitmap btp = new Bitmap(img, _width, _height);

        DirectoryInfo dti = new DirectoryInfo(fileFoldUrl);

        FileInfo[] fis = dti.GetFiles();

        string fileUrl = fileFoldUrl + fileName;

        btp.Save(fileUrl);
    }

    /// <summary>
    /// 获取指定文件流的字节大小
    /// </summary>
    /// <param name="filePath">文件路径</param>
    /// <returns>byte[]</returns>
    public byte[] load_pictMemory(string filePath)
    {
        byte[] pictData = null;

        FileInfo fi = new FileInfo (filePath);

        if (fi.Exists)
        {
            pictData = new byte[fi.Length];

            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);

            BinaryReader br = new BinaryReader(fs);

            br.Read(pictData, 0, Convert.ToInt32(fi.Length));

            fs.Dispose();
        }
        else
        {
            HttpContext.Current.Response.Write("<script language='javascript'>alert('没有找到你所指定的图片')</script>");
        }
        return pictData;
    }

  • 相关阅读:
    BigDecimal 使用方法详解
    vbs xml 解析
    hybris
    淘宝SKU组合查询算法实现
    GitHub入门教程 Hello World for GitHub
    利用Java进行MySql数据库的导入和导出
    计算机网络自顶向下第三章传输层二TCP
    django网站搭建常用的一些代码
    django中日志使用学习记录
    python遍历当前目录并删除某文件
  • 原文地址:https://www.cnblogs.com/gracexy/p/4725367.html
Copyright © 2020-2023  润新知