protected void Button5_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            //TextBox10.Text = FileUpload1.ToString();
            String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName);
            fileExtension = fileExtension.ToLower();
            String filename = getUserId + i + fileExtension;
            FileUpload1.PostedFile.SaveAs(Server.MapPath("./UploadImages/") + filename);
            PicPath = "F:/SimpleWeibo/WebUI/UploadImages/" + filename;
            TextBox3.Text = PicPath;            /*if (fileExtension == ".gif" || fileExtension == ".png" || fileExtension == ".jpg" || fileExtension == ".bmp")
            {                if (FileUpload1.PostedFile.ContentLength < 10485760)
                {
                    try
                    {
                        i = i + 1;
                        String itos = i.ToString();
                        String fileName = getUserId +itos+ fileExtension;
                        FileUpload1.PostedFile.SaveAs(Server.MapPath("./UploadImages/") + fileName);                        PicPath = "F:/SimpleWeibo/WebUI/UploadImages/" + fileName;
                        //String smallPicPath = "F:/SimpleWeibo/WebUI/UploadImages/small" + fileName;
                        System.Drawing.Image originalImage = System.Drawing.Image.FromFile(PicPath);                        int ow = originalImage.Width;
                        int oh = originalImage.Height;                        /*if (ow > 55 || oh > 55)
                        {
                            MakeThum makePicSmall = new MakeThum();
                            makePicSmall.MakeThumbnail(bigPicPath, smallPicPath, 48, 48, false);
                        }*/            /*注意->这里为什么不是:FileUpLoad1.PostedFile.FileName 
            * 而是:FileUpLoad1.FileName? 
            * 前者是获得客户端完整限定(客户端完整路径)名称 
            * 后者FileUpLoad1.FileName只获得文件名. 
            */
            //Response.Write("<img name='' src=PicPath width='170' height='300' alt='' />");            /*            UploadAlert.Text = "上传成功!";
                    }
                    catch (Exception ex)
                    {
                        UploadAlert.Text = "出现异常,无法上传!";
                        UploadAlert.Text += ex.ToString();
                    }                }
                else
                {
                    UploadAlert.Text = "上传文件不能大于10MB!";
                }
            }
            else
            {
                UploadAlert.Text = "文件类型不正确!";
            }
        }
        else
        {
            UploadAlert.Text = "尚未选择文件!";
        }*/
        }
    }
    protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
    {
        //获取原始图片 
        System.Drawing.Image originalImage = System.Drawing.Image.FromFile(PicPath);
        //原始图片写入画布坐标和宽高(用来设置裁减溢出部分) 
        int x = 0;
        int y = 0;
        int ow = originalImage.Width;
        int oh = originalImage.Height;
        //原始图片画布,设置写入缩略图画布坐标和宽高(用来原始图片整体宽高缩放) 
        int bg_x = 0;
        int bg_y = 0;
        int bg_w = 100;
        int bg_h = 100;
        //倍数变量 
        double multiple = 0;
        //获取宽长的或是高长与缩略图的倍数 
        if (originalImage.Width >= originalImage.Height)
            multiple = (double)originalImage.Width / 100;
        else
            multiple = (double)originalImage.Height / 100;
        //上传的图片的宽和高小等于缩略图 
        if (ow <= 100 && oh <= 100)
        {
            //缩略图按原始宽高 
            bg_w = originalImage.Width;
            bg_h = originalImage.Height;
            //空白部分用背景色填充 
            bg_x = Convert.ToInt32((100 - (double)ow) / 2);
            bg_y = Convert.ToInt32((100 - (double)oh) / 2);
        }
        //上传的图片的宽和高大于缩略图 
        else
        {
            //宽高按比例缩放 
            bg_w = Convert.ToInt32((double)originalImage.Width / multiple);
            bg_h = Convert.ToInt32((double)originalImage.Height / multiple);
            //空白部分用背景色填充 
            bg_y = Convert.ToInt32((100 - (double)bg_h) / 2);
            bg_x = Convert.ToInt32((100 - (double)bg_w) / 2);
        }
        //新建一个bmp图片,并设置缩略图大小. 
        System.Drawing.Image bitmap = new System.Drawing.Bitmap(100, 100);
        //新建一个画板 
        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
        g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
        //设置高质量插值法 
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        //设置高质量,低速度呈现平滑程度
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        //清空画布并设置背景色 
        g.Clear(System.Drawing.ColorTranslator.FromHtml("#FFF"));
        //第一个System.Drawing.Rectangle是原图片的画布坐标和宽高,第二个是原图片写在画布上的坐标和宽高,最后一个参数是指定数值单位为像素 
        g.DrawImage(originalImage, new System.Drawing.Rectangle(bg_x, bg_y, bg_w, bg_h), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel);
    }
}
怎么修改可以在我的imagebotton上显示上传的图片?

解决方案 »

  1.   

    上传后返回一个图片的路径,再在imagebutton上显示。
      

  2.   

    上传成功你有图片路径和图片名,返回给imagebutton就可以了
      

  3.   

    imagebotton上显示上传的图片?什么意思?
    你是想点击imagebotton实现上传图片预览嘛?
    js操作http://www.cnblogs.com/JieNet/archive/2010/03/18/988117.html
      

  4.   

    this.Label1.Text += "<hr width=\"720px\"><br/><div align=\"left\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td>";
                    this.Label1.Text += statements[i];
                    this.Label1.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    this.Label1.Text += timeDif;
                   // this.Label1.Text += "<a href =";
                    this.Label1.Text += "<asp:ImageButton ID=\"\" runat=\"server\" width=\"20px\" height=\"20px\" ImageUrl=\"~/UploadImages/f.jpg\"/>";
                    this.Label1.Text += "</div><br/><br/><td>";
    这段代码为什么显示不了 imagebotton的啊!?
      

  5.   

    把你的Label1用div来代码,通过添加run=server来声明为服务器控件再通过innerhtml来把你的代码添加到页面。
      

  6.   

    是这样的我想在生成的label中间建立一个(imagebotton)但是试过好像不行,最后用这种方式this.Label1.Text += "<input type=\"image\" name=\"";建立了一个(image),但是我始终想新生成的label里建立一个可以点击的imagebotton 行吗?哪位大神给一下具体代码
      

  7.   

    imagebotton上传图片显示的问题已经解决了 我想在html页面显示的时候建立一个imagebotton 而不是image 可以建立吗?
      

  8.   

    可以建立imagebotton数据 用于装载一堆imagebotton吗?然后将其高度置值!