更新面板图像 - 问题 [英] Update Panel Image - Problem

查看:77
本文介绍了更新面板图像 - 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我希望将图像转角然后在updatePanel中显示...

没有圆角功能它工作正常......但是当我运行圆角图像的功能时,给出文件未找到错误()



我的代码

 protected void Timer1_Tick(对象发送者,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(路径)+' alt =' ' / > < /跨度>;
using(System.Drawing.Image imgin = System.Drawing.Image.FromFile(path))
{
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imgin.Width ,imgin.Height);
图形g = Graphics.FromImage(位图);
g.Clear(Color.White);
Brush brush = new System.Drawing.TextureBrush(imgin);
FillRoundedRectangle(g,new Rectangle(0,0,imgin.Width,imgin.Height),roundedDia,brush);
//使用绘图处理图形对象完成。
g.Dispose();
//将图像流映射到客户端。
Response.Clear();
Response.ContentType =image / pjpeg;
bitmap.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
Response.End();
//配置位图对象。
bitmap.Dispose(); / *可能在这里* /
}
LtrImg.Text =< img src =' + Page.ResolveUrl(路径)+' alt =' ' / > ;
}



感谢指导..

解决方案

请参考下文关于使用HTTP处理程序提供动态内容的链接。

部分 - 创建ImageHandler HTTP处理程序



http://msdn.microsoft.com/en-us/library/ms972953.aspx [ ^ ]



希望这可能有助于解决这个问题。


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



  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 );
会话[ ImgId] = Indx.ToString();
Image1.ImageUrl = ImgWebForm.aspx?ImgId = + Indx.ToString() 。修剪();
}





然后

 ImgWebForm.aspx Page_Load ()
{
string ImgFileId = Session [ImgId]。ToString();
switch(ImgFileId)
{
case1:
path = Server.MapPath(〜/ MyImages / Picture1.jpg);
休息;
case2:
path = Server.MapPath(〜/ MyImages / Picture2.jpg);
休息;
case3:
path = Server.MapPath(〜/ MyImages / Picture3.jpg);
休息;
}
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);
图形g = Graphics.FromImage(位图);
g.Clear(Color.White);
Brush brush = new System.Drawing.TextureBrush(imgin);
FillRoundedRectangle(g,new Rectangle(0,0,imgin.Width,imgin.Height),roundedDia,brush);
//使用绘图处理图形对象完成。
g.Dispose();
//将图像流映射到客户端。
Response.Clear();
Response.ContentType =image / pjpeg;
bitmap.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
Response.End();
//配置位图对象。
bitmap.Dispose();
}
public static void FillRoundedRectangle(Graphics g,Rectangle r,int d,Brush b)
{
// anti alias distorts fill如此删除它。
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;
}





让对我这样的人有用..

谢谢...


Hi, Actually I wish to round corner the Image and then display it in updatePanel...
Without roundcorner functions it's working fine...But when I run the functions for round corner image, its giving File Not Found Error()

My Codes

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=''/>";
     }


Thanks for the guidances..

解决方案

Please refer below link regarding "Serving Dynamic Content with HTTP Handlers".
Section - Creating the ImageHandler HTTP Handler

http://msdn.microsoft.com/en-us/library/ms972953.aspx[^]

Hope this might be helpful to solve this problem.


Anyhow I succeeded by the following way..

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(); 
         }



and then

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;
        }



Let it be useful to someoneelse like me..
Thankyou ...


这篇关于更新面板图像 - 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆