• 如何在C#中实现图片缩放


    //************************************************************//
    //下面给出三个简单的方法,后面两个方法是扩展,估计有时用得着
    //************************************************************//
    /// <summary>
    /// 缩小图片
    /// </summary>
    /// <param name="stroldpic">源图文件名(包括路径)</param>
    /// <param name="strnewpic">缩小后保存为文件名(包括路径)</param>
    /// <param name="intwidth">缩小至宽度</param>
    /// <param name="intheight">缩小至高度</param>
    public void smallpic(string stroldpic, string strnewpic, int intwidth, int intheight)
    {

    system.drawing.bitmap objpic,objnewpic;
    try
    {
    objpic = new system.drawing.bitmap(stroldpic);
    objnewpic=new system.drawing.bitmap(objpic,intwidth,intheight);
    objnewpic.save(strnewpic);

    }
    catch(exception exp){throw exp;}
    finally
    {
    objpic=null;
    objnewpic=null;
    }
    }

    /// <summary>
    /// 按比例缩小图片,自动计算高度
    /// </summary>
    /// <param name="stroldpic">源图文件名(包括路径)</param>
    /// <param name="strnewpic">缩小后保存为文件名(包括路径)</param>
    /// <param name="intwidth">缩小至宽度</param>
    public void smallpic(string stroldpic, string strnewpic, int intwidth)
    {

    system.drawing.bitmap objpic,objnewpic;
    try
    {
    objpic = new system.drawing.bitmap(stroldpic);
    int intheight=(intwidth / objpic.width) * objpic.height;
    objnewpic=new system.drawing.bitmap(objpic,intwidth,intheight);
    objnewpic.save(strnewpic);

    }
    catch(exception exp){throw exp;}
    finally
    {
    objpic=null;
    objnewpic=null;
    }
    }


    /// <summary>
    /// 按比例缩小图片,自动计算宽度
    /// </summary>
    /// <param name="stroldpic">源图文件名(包括路径)</param>
    /// <param name="strnewpic">缩小后保存为文件名(包括路径)</param>
    /// <param name="intheight">缩小至高度</param>
    public void smallpic(string stroldpic, string strnewpic, int intheight)
    {

    system.drawing.bitmap objpic,objnewpic;
    try
    {
    objpic = new system.drawing.bitmap(stroldpic);
    int intwidth=(intheight / objpic.height) * objpic.width;
    objnewpic=new system.drawing.bitmap(objpic,intwidth,intheight);
    objnewpic.save(strnewpic);

    }
    catch(exception exp){throw exp;}
    finally
    {
    objpic=null;
    objnewpic=null;
    }
    }

  • 相关阅读:
    1026. 程序运行时间(15)
    C语言字符串/数组去重
    1025. 反转链表 (25)
    1024. 科学计数法 (20)
    1023. 组个最小数 (20)
    1022. D进制的A+B (20)
    1021. 个位数统计 (15)
    1020. 月饼 (25)
    前端001/正则表达式
    SSM001/构建maven多模块项目
  • 原文地址:https://www.cnblogs.com/codeloves/p/3088168.html
Copyright © 2020-2023  润新知