ITPub博客

首页 > 应用开发 > IT综合 > APS.NET把读取的图片用图片空间压缩显示

APS.NET把读取的图片用图片空间压缩显示

原创 IT综合 作者:scy072 时间:2015-02-11 09:13:21 0 删除 编辑
假定在Image控件中想把图片的宽度显示为固定值600,超出600的压缩显示宽高,不足600的原图显示:
FileStream fs = new FileStream(Server.MapPath(txtPicUrl), FileMode.Open, FileAccess.Read); --txtPicUrl为图片在服务器上的物理路径如:~\Pic
System.Drawing.Image image = System.Drawing.Image.FromStream(fs);
int width = Convert.ToInt32(image.Width.ToString());
double height = Convert.ToInt32(image.Height.ToString());
 if (width > 600)
{
     height = Math.Round(height * 600 / width);
}

this.img.ImageUrl =txtPicUrl;
this.img.Width = 600;
this.img.Height = (int)height;

img为.aspx文件界面中Image控件的ID

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26189725/viewspace-1432961/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-01-23

  • 博文量
    14
  • 访问量
    20649