试了2种办法,但都无效?需求:判断图片控件的尺寸,如超过指定大小,则调整
1、
 System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
                    img.ImageUrl=slArticle["article_Pics"].ToString();
                    if (img.Width.Value>60)
                    {
                        img.Width=Unit.Pixel(60);
                    }
                    this.Panel1.Controls.Add(img);
2、
                    this.Image1.Visible=true;
                    this.Image1.ImageUrl=slArticle["article_Pics"].ToString();
                    if (this.Image1.Width.Value>60)
                    {
                        this.Image1.Width=Unit.Pixel(60);
                    }
                    this.Response.Write(img.Width.Value);

解决方案 »

  1.   

    应该用图片本身的宽度去比较
    using(Image img = Image.FormFile(filePath))
    {
        if(img.Width >60)
       {
          this.Image1.Width=Unit.Pixel(60);
       }
    }
      

  2.   

    using(Image img = Image.FormFile(filePath))在MSDN中没找到相应的方法?
      

  3.   

    参考下面的方法:
    // 使用缩略图需要的回调函数。空,不做任何动作
    public static bool ThumbnailCallback()
    {return false;}
    调用:
    if(System.IO.File.Exists(ImgPath))
    {
    Image.GetThumbnailImageAbort myCallback =new Image.GetThumbnailImageAbort(ThumbnailCallback);
    Image simg=Image.FromFile(si.ImgPath).GetThumbnailImage( PictureBox1.Width, PictureBox1.Height, myCallback, IntPtr.Zero);
    PictureBox1.Image=simg;