如何在asp.net c中将URL转换为图像# [英] how to convert URL to image in asp.net c#

查看:63
本文介绍了如何在asp.net c中将URL转换为图像#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,我需要开发基于Web的系统,这是我的项目文件的Web应用程序。因为它我必须将URL转换为网站中的图像。也就是说,首先我必须在文本框中插入URL,然后单击浏览按钮。点击后,它必须显示URL的图像。我需要这个代码。我找不到任何要转换的代码。请帮我。我在VS 2010终极中使用asp.net c#。

解决方案

URL是文件的地址,无论是本地(您的网络服务器)还是远程(某些人)网络服务器)。 URL指向图像,与文件路径和文件名指向硬盘驱动器上的文件的方式相同。该URL允许您的Web应用程序在网页上显示图像。



例如:

远程图片:
< div >
< img src = http:// someremotewebsite。 com / images / remoteImage.jpg alt = 如果图像未显示,则显示备用文本 / >
< / div >

本地映像(假设使用.NET Framework):
< div >
< img src = < span class =code-keyword>〜/ images / localImage.jpg alt = 备用文字,以防您的图片无法显示 >
< / img > < / div >


你可以像这样创建....





 <   html     xmlns   =  http://www.w3.org/1999/xhtml >  
< head runat = 服务器 >
< title > < / title >
< /头 >
< body >
< 表单 id = < span class =code-keyword> form1
runat = server >
< div >
< asp: script manager id = ScriptManager runat = 服务器 >
< / asp: script manager > ;
< asp:updatepanel id = UpdatePanel runat = server >
< contenttemplate >
< 表格 >
< tr >
< td >
< asp:textbox id = txtImgUrl runat = 服务器 > < / asp:textbox >
< / td >
< td >
< asp:按钮 id = btnShow runat = server text = 显示 onclick = btnShow_Click / >
< / td >
< / tr >
< tr >
< td >
< asp:label id = lblMessage runat = server 可见 = false > < / asp:label >
< / td >
< / tr >
< / table >
< br / >
< div >
< asp:image id = imgView runat < span class =code-keyword> =
server alternatetext = Image Goes Here visible = false / >
< / div >
< / contenttemplate >
< / asp:updatepanel >
< / div >
< / form &g t;
< / body >
< / html >





和背后的代码如...



  protected   void  btnShow_Click( object  sender,EventArgs e)
{
if (!string.IsNullOrEmpty(txtImgUrl.Text) )
{
imgView.ImageUrl = txtImgUrl.Text;
imgView.Visible = true ;
}
else
{
lblMessage.Visible = true ;
lblMessage.Text = 请将网址添加到文本框;
}
}





并使用像这样的图片网址...



https://www.google.co.in/images/srpr/ logo11w.png [ ^ ]


HI, i need to develop web based system that are web application for my project paper. for it i have to convert URL to image in website. That are, firstly i must insert URL in textbox then click browse button. Once click it have to show the images of the URL. Please i need code for this. i could not find any code to convert. Please help me. Im using asp.net c# in VS 2010 ultimate.

解决方案

A URL is an address to a file, whether it is local (your webserver) or remote (someone elses webserver). A URL "points" to an image, in the same way that a file path and file name points to a file on your hard drive. The URL allows your web application to display the image on a web page.

For example:

 Remote image:
 <div>
     <img src="http://someremotewebsite.com/images/remoteImage.jpg" alt="Alternate text in case your image does not display" />
 </div>

Local image (assumes using .NET Framework) :
 <div>
      <img src="~/images/localImage.jpg" alt="Alternate text in case your image does not display">
 </img></div>


you can create like this....


<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:scriptmanager id="ScriptManager" runat="server">
        </asp:scriptmanager>
        <asp:updatepanel id="UpdatePanel" runat="server">
            <contenttemplate>
                <table>
                    <tr>
                        <td>
                            <asp:textbox id="txtImgUrl" runat="server"></asp:textbox>
                        </td>
                        <td>
                            <asp:button id="btnShow" runat="server" text="Show" onclick="btnShow_Click" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:label id="lblMessage" runat="server" visible="false"></asp:label>
                        </td>
                    </tr>
                </table>
                <br />
                <div>
                    <asp:image id="imgView" runat="server" alternatetext="Image Goes Here" visible="false" />
                </div>
            </contenttemplate>
        </asp:updatepanel>
    </div>
    </form>
</body>
</html>



and code behind like...

protected void btnShow_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtImgUrl.Text))
            {
                imgView.ImageUrl = txtImgUrl.Text;
                imgView.Visible = true;
            }
            else
            {
                lblMessage.Visible = true;
                lblMessage.Text = "Please add Url to text box";
            }
        }



and use image url like this...

https://www.google.co.in/images/srpr/logo11w.png[^]


这篇关于如何在asp.net c中将URL转换为图像#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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