如何控制图像的重新加载 [英] How to control the reloading of an image

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

问题描述

我的页面上有一张图片.

我希望在单击刷新"按钮时重新加载该图像,因为当我单击刷新"按钮时,图片的内容将会更改.

请帮帮我.

在此先感谢!

I have an image on my page.

I want this image to reload when I click on button "Refresh" because when I click on button "Refresh", the content of the picture will change.

Help me please.

Thanks in advance!

推荐答案

1.那么刷新按钮到底有什么作用?
2.是请求新页面还是正在对服务器进行AJAX调用?
3.如何递送图像(从Web服务器文件(.jpg,.png等)或通过aspx/asmx页面
4.图片内容改变是什么意思?
这是否意味着将生成图片,还是要显示另一个已经存在的图像.

请详细说明您的问题,因为就目前情况而言,您知道获得答案的机会不大.

干杯!
1. So the refresh button does exactly what?
2. Is a new page requested or is an AJAX call being made to the server?
3. How is the image delivered (from webserver file (.jpg,.png, etc.) or via an aspx/asmx page
4. What do you mean by the content of the picture changed?
Does it mean the picture will be generated or do you want to display another already existing image.

Please elaborate on your question because as it stands right know your chances of getting an answer are more than slim.

Cheers!


尝试以下操作:
xyz.aspx

Try the following:
xyz.aspx

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:Image ID="imgContainer" runat="server" Height="51px" Width="212px" />
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="imbReLoad" />
                        </Triggers>
                    </asp:UpdatePanel>
                    <asp:ImageButton ID="imbReLoad" runat="server" Height="31px" ImageUrl="image url here"

                        OnClick="imbReLoad_Click" Width="33px" />



xyz.cs



xyz.cs

protected void imbReLoad_Click(object sender, ImageClickEventArgs e)
   {
       //call function to refresh image
       
   }


我希望我能收到您的帮助,谢谢.
我的代码如下:
I hope that I will receive your help, thanks.
my code as below:
<asp:Image ID="imgCapcha" runat="server" Height="51px" Width="212px" />
               <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
               <ContentTemplate >
                &nbsp;&nbsp;&nbsp;
               <asp:ImageButton ID="imbReLoad" runat="server" Height="31px"

                   ImageUrl="~/hinhtrangtri/refresh.png" OnClick="imbReLoad_Click"

                   Width="33px" />
               </ContentTemplate>
             </asp:UpdatePanel>



并在以下类代码处进行编码:



and code at class codebehind:

// code create image capchar
    public void TaoAnhCapcha()
    {
        string[] Fonts = { "Arial Black", "Arial" };
        byte bLenght = 6;
        string chars = "12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabdeqptmnghr"; ;
        Bitmap bmp = new Bitmap(125, 30);
        Graphics gr = Graphics.FromImage(bmp);
        // chọn kiểu hiển thị của bipmap kiểu gợn sóng
        // choose type of bipmap
        HatchBrush brush = new HatchBrush(HatchStyle.Wave, Color.White, Color.Wheat);
        gr.FillRegion(brush, gr.Clip);
        //Lưu chuỗi capcha trong quá trình tạo
        StringBuilder strCapCha = new StringBuilder();
        Random Rand = new Random();
        int x = 1;
        for (int i = 0; i < bLenght; i++)
        {
            // Lấy ký tự ngẫu nhiên từ mảng chars
            // get ramdom char
            string schar = chars[Rand.Next(chars.Length)].ToString();
            strCapCha.Append(schar);
            // Tạo font với font ngẫu nhiên chọn từ Fonts
            //create font with ramdom font
            Font font = new Font(Fonts[Rand.Next(Fonts.Length)], 12, FontStyle.Bold | FontStyle.Italic);
            //Lầy kích thước của ký tự
            //get the size of char
            SizeF size = gr.MeasureString(schar, font);
            // Vẽ Ký tự ra ảnh theo thứ tự tăng dần với tọa độ X tăng dần theo i và Y ngẫu nhiên
            //draw char to image
            gr.DrawString(schar, font, Brushes.Blue, x * 2, Rand.Next(2, 10));
            font.Dispose();
            x += 10;
        }
        // Lưu captcha vào session 
        //save capchar to session
        Session["captcha"] = strCapCha.ToString();
        //// Lưu ảnh vào thư mục Capcha với tên ảnh dựa theo IP 
        //save image into folder "hinhtrangtri"
        string path = "hinhtrangtri/" + Request.UserHostAddress + ".gif";
        bmp.Save(Server.MapPath("") + "/" + path, System.Drawing.Imaging.ImageFormat.Gif);
                    
        imgCapcha.ImageUrl = path; // it is not refresh the content of image capchar
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //call function create image capchar
            TaoAnhCapcha();     
        }
    }
    // when user click on this image button, it create new a capchar (the same refresh this image capchar)
    protected void imbReLoad_Click(object sender, ImageClickEventArgs e)
    {
        //CreateCaptcha();
        //call function create image capchar
        TaoAnhCapcha();
    }


这篇关于如何控制图像的重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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