zoukankan      html  css  js  c++  java
  • 如何在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;
    }
    }
    

     摘自:http://www.alixixi.com/program/a/2008020624216.shtml

  • 相关阅读:
    P2711 小行星 最小割
    bzoj2141: 排队 cdq分治
    bzoj 4237: 稻草人 cdq分治
    P1527 [国家集训队]矩阵乘法 整体二分
    P2617 Dynamic Rankings 整体二分
    P3834 【模板】可持久化线段树 1(主席树) 整体二分
    SPREAD for Windows Forms 代码片段
    PHP+Oracle Instant Client
    SQL利用CASE按分组显示合计
    SPREAD for Windows Forms 控制输入法
  • 原文地址:https://www.cnblogs.com/shirley-1019/p/3230454.html
Copyright © 2011-2022 走看看