0

实际上我希望对图像进行圆角,然后将其显示在 updatePanel 中...没有圆角功能它工作正常...但是当我运行圆角图像的函数时,它给出 File Not Found Error()

我的代码

 protected void Timer1_Tick(object sender, EventArgs e)
        {
            NameValueCollection MyImgList = new NameValueCollection();
            MyImgList.Add("Img1", "~/MyImages/Picture1.jpg");
            MyImgList.Add("Img2", "~/MyImages/Picture2.jpg");
            MyImgList.Add("img3", "~/MyImages/Picture3.jpg");
            Random Rnd = new Random();
            int Indx = Rnd.Next(0, 4);
            path = MyImgList[Indx].ToString();
            //LtrImg.Text = "<img src='" + Page.ResolveUrl(path) + "' alt=''/>";
            using (System.Drawing.Image imgin = System.Drawing.Image.FromFile(path))
            {
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imgin.Width, imgin.Height);
                Graphics g = Graphics.FromImage(bitmap);
                g.Clear(Color.White);
                Brush brush = new System.Drawing.TextureBrush(imgin);
                FillRoundedRectangle(g, new Rectangle(0, 0, imgin.Width, imgin.Height), roundedDia, brush);
                // done with drawing dispose graphics object.
                g.Dispose();
                // Stream Image to client.
                Response.Clear();
                Response.ContentType = "image/pjpeg";
                bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                Response.End();
                // dispose bitmap object.
                bitmap.Dispose();   /* May be Here */
            }
            LtrImg.Text = "<img src='" + Page.ResolveUrl(path) + "' alt=''/>";
      }

谢谢指导。。

4

1 回答 1

0

无论如何,我通过以下方式成功了..

protected void Timer1_Tick(object sender, EventArgs e)
        {   NameValueCollection MyImgList = new NameValueCollection();
            MyImgList.Add("MyImage1", "~/MyImages/Picture1.jpg");
            MyImgList.Add("MyImage2", "~/MyImages/Picture2.jpg");
            MyImgList.Add("MyImage3", "~/MyImages/Picture3.jpg");
            Random Rnd = new Random();
            int Indx = Rnd.Next(0, 4);
            Session["ImgId"] = Indx.ToString();
            Image1.ImageUrl = "ImgWebForm.aspx?ImgId="+Indx.ToString().Trim(); 
         }

进而

ImgWebForm.aspx Page_Load()
{
string ImgFileId = Session["ImgId"].ToString();
            switch (ImgFileId)
            {
                case "1":
                    path = Server.MapPath("~/MyImages/Picture1.jpg");
                    break;
                case "2":
                    path = Server.MapPath("~/MyImages/Picture2.jpg");
                    break;
                case "3":
                    path = Server.MapPath("~/MyImages/Picture3.jpg");
                    break;
            }
            int roundedDia = 50;
            using (System.Drawing.Image imgin = System.Drawing.Image.FromFile(path))
            {
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imgin.Width, imgin.Height);
                Graphics g = Graphics.FromImage(bitmap);
                g.Clear(Color.White);
                Brush brush = new System.Drawing.TextureBrush(imgin);
                FillRoundedRectangle(g, new Rectangle(0, 0, imgin.Width, imgin.Height), roundedDia, brush);
                // done with drawing dispose graphics object.
                g.Dispose();
                // Stream Image to client.
                Response.Clear();
                Response.ContentType = "image/pjpeg";
                bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                Response.End();
                // dispose bitmap object.
                bitmap.Dispose();
            }
public static void FillRoundedRectangle(Graphics g, Rectangle r, int d, Brush b)
        {
            // anti alias distorts fill so remove it.
            System.Drawing.Drawing2D.SmoothingMode mode = g.SmoothingMode;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
            g.FillPie(b, r.X, r.Y, d, d, 180, 90);
            g.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90);
            g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90);
            g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
            g.FillRectangle(b, r.X + d / 2, r.Y, r.Width - d, d / 2);
            g.FillRectangle(b, r.X, r.Y + d / 2, r.Width, r.Height - d);
            g.FillRectangle(b, r.X + d / 2, r.Y + r.Height - d / 2, r.Width - d, d / 2);
            g.SmoothingMode = mode;
        }

让它对像我这样的人有用..谢谢...

于 2013-08-27T12:52:49.077 回答