我想c#缩小图片, 是等比例的。 但是我又要框死声称图片大小为 100 X 100, 我缩放的话是用 img.width和img.height
的比较确定 生成图片的width和height 谁是100。 然后等比例缩小长宽, 但是那样的话
Image bitmap = new Bitmap(size.Width, size.Height); 这个图本生就只能是100X xx或者 xx X 100了。 有没办法将图还是100X100 生成缩略图在他的中央显示。 

解决方案 »

  1.   

    图片缩略图
    GetThumbnailImage是用来产生缩略图的
    等比例缩放图片
    等比例缩放图片
    <script language="JavaScript">
    var flag=false;
    function DrawImage(ImgD,iwidth,iheight){
      var image=new Image();
      image.src=ImgD.src;
      if(image.width>0 && image.height>0){
      flag=true;
      if(image.width/image.height>= iwidth/iheight){
      if(image.width>iwidth){   
      ImgD.width=iwidth;
      ImgD.height=(image.height*iwidth)/image.width;
      }else{
      ImgD.width=image.width;   
      ImgD.height=image.height;
      }
      ImgD.alt=image.width+"×"+image.height;
      }
      else{
      if(image.height>iheight){   
      ImgD.height=iheight;
      ImgD.width=(image.width*iheight)/image.height;   
      }else{
      ImgD.width=image.width;   
      ImgD.height=image.height;
      }
      ImgD.alt=image.width+"×"+image.height;
      }
    }
    }