欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【.Net上传图片按比例自动缩小或放大】,下面是详细的分享!
.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;
}
}
以上所分享的是关于.Net上传图片按比例自动缩小或放大,下面是编辑为你推荐的有价值的用户互动:
相关问题:在PS中如何等比例放大缩小图片
答:在图层面板选中图片所在图层。ctrl+t自由变换,可以看到边上有九个点,按住shift,之后鼠标在四个角的点拉伸。就可以等比例缩放。缩放同时按住alt可改变图片缩放的中心点 >>详细
相关问题:有关PS的 在PS里 想把一张照片缩小或放大时 如何让...
答:可以在属性栏中设置相同长宽缩放比例,或者CTRL+T后,按住SHIFT键拉四角任何一调节点也行。 >>详细
相关问题:ps调整图片大小时如何对图片等比例放大或者缩小?
答:按住shift拖动变换框即可 按住shift+Alt拖动是以中心点为基点进行等比例缩放。 在进行缩放操作的时候,最好能将对象“转换为智能对象”(右键图层即可),这是一种无损编辑模式,缩小后的图片再放大也不会出现失真。 >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
