安比例缩放图片

1.图像在存储前就要压缩,jpg本来就是压缩后的格式,所只把图像存为jpg  
  if(IsProportion)  
  {  
  //图像按比较缩放  
  if(imgWidth>imgHeight)  
  {  
  //图像形装是横长方形  
  picWidth=width; //此处设置图片宽度参数  
  picHeight=(imgHeight/imgWidth)*picWidth; //按比例缩放图片  
  }//   end   if  
  else   if(imgWidth.Equals(imgHeight))  
  {  
  //图像形状是正方形  
  picWidth=width; //按指定的宽度缩放图片  
  picHeight=height; //按指定的高度缩放图片  
  }//   end   else   if  
  else  
  {  
  //图像形状是竖长方形  
  picHeight=width; //此处设置图片高度参数  
  picWidth=(imgWidth/imgHeight)*picHeight; //按比例缩放图片  
  }//   end   else  
  }//   end   if  
  else  
  {  
  //图像按指定的尺寸缩放  
  picWidth=width; //按指定的宽度缩放图片  
  picHeight=height; //按指定的高度缩放图片  
  }//   end   else  
  //以新图像大小创建一块画布  
  using(   System.Drawing.Bitmap   bitmap   =   new   System.Drawing.Bitmap(   (int)picWidth   ,(int)picHeight,   PixelFormat.Format32bppArgb)) //using   3  
  {  
   
  using(   System.Drawing.Graphics   graphics   =   System.Drawing.Graphics.FromImage(   bitmap   )   ) //using   4  
  {  
  //清除整个绘图面并以透明背景色填充  
  graphics.Clear(   Color.Transparent   );  
  //在指定位置并且按指定大小绘制   原图片   对象  
  graphics.DrawImage(img,   new   Rectangle(0,   0,(int)picWidth,   (int)picHeight));  
  bitmap.Save(Stream2,System.Drawing.Imaging.ImageFormat.Jpeg); 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值