.Net实现上传图片按比例自动缩小或放大的方法
本文实例主要展示了.Net实现上传图片按比例自动缩小或放大的方法,是非常实用的功能。分享给大家供大家参考之用。具体方法如下:
////<summary>
///按比例缩小图片,自动计算宽度
///</summary>
///<paramname="strOldPic">源图文件名(包括路径)</param>
///<paramname="strNewPic">缩小后保存为文件名(包括路径)</param>
///<paramname="intHeight">缩小至高度</param>
publicvoidSmallPicWidth(stringstrOldPic,stringstrNewPic,intintHeight)
{
System.Drawing.BitmapobjPic,objNewPic;
try
{
objPic=newSystem.Drawing.Bitmap(strOldPic);
intintWidth=(intHeight/objPic.Height)*objPic.Width;
objNewPic=newSystem.Drawing.Bitmap(objPic,intWidth,intHeight);
objNewPic.Save(strNewPic);
}
catch(Exceptionexp){throwexp;}
finally
{
objPic=null;
objNewPic=null;
}
}
/**////<summary>
///缩小图片
///</summary>
///<paramname="strOldPic">源图文件名(包括路径)</param>
///<paramname="strNewPic">缩小后保存为文件名(包括路径)</param>
///<paramname="intWidth">缩小至宽度</param>
///<paramname="intHeight">缩小至高度</param>
publicvoidSmallPic(stringstrOldPic,stringstrNewPic,intintWidth,intintHeight)
{
System.Drawing.BitmapobjPic,objNewPic;
try
{
objPic=newSystem.Drawing.Bitmap(strOldPic);
objNewPic=newSystem.Drawing.Bitmap(objPic,intWidth,intHeight);
objNewPic.Save(strNewPic);
}
catch(Exceptionexp)
{throwexp;}
finally
{
objPic=null;
objNewPic=null;
}
}
希望本文所述实例对大家的asp.net程序设计有一定的借鉴价值。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下