用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > Net教程

.Net实现上传图片按比例自动缩小或放大的方法

时间:2015-01-29  来源:互联网  作者:佚名

本文实例主要展示了.Net实现上传图片按比例自动缩小或放大的方法,是非常实用的功能。分享给大家供大家参考之用。具体方法如下:

//// <summary>
/// 按比例缩小图片,自动计算宽度
/// </summary>
/// <param name="strOldPic">源图文件名(包括路径)</param>
/// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>
/// <param name="intHeight">缩小至高度</param>
public void SmallPicWidth(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;
  }
}
/**//// <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;
  }
}

希望本文所述实例对大家的asp.net程序设计有一定的借鉴价值。

来顶一下
返回首页
返回首页
推荐资讯
.net非托管资源的回收方法 .net非托管资源的回收方法本文实例讲述了.net非托管资源的回收方法,分享给大家供大家
AspNetPager控件的最基本用法示例介绍 AspNetPager控件的最基本用法示例介AspNetPager控件是一个基于.net的第三方免费开源控件,具有开
相关文章
栏目更新
栏目热门