从其他网站提取图像 [英] Extract image from other websites
本文介绍了从其他网站提取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用c#
推荐答案
从其他网站提取图像并将其显示在asp.net的gridview中,步骤1:从网站提取图像
看看这个线程讨论 [ ^ ] 相同.
提取图像后,需要将其存储在本地或您喜欢的位置.
步骤2:现在,获取所有存储的图像,以在gridview中显示它.这是在互联网上经过充分讨论的大量文章. CP本身很少在这里.
试试吧!
Step 1: Extract images from a website
Have a look at this thread discussing[^] the same.
Once you extract the images, you need to store it locally or somewhere you like to.
Step 2: Now, fetch the images wherever stored to show it in a gridview. This is a well discussed over internet with lots of articles. Few are here at CP itself.
Try!
例如......
您可能有一个单独的aspx文件,并且在页面加载事件中有此代码..
Hi,
As an example....
You may have a separate aspx file and at it''s page load event have this code..
protected void Page_Load(object sender, EventArgs e)
{
string path = Request.QueryString["image_path"];
Response.ContentType = "image/jpg";
WebRequest objReq = WebRequest.Create(path);
WebResponse objResp = objReq.GetResponse();
Stream objStream = objResp.GetResponseStream();
int length = (int)objResp.ContentLength;
BinaryReader reader = new BinaryReader(objStream, Encoding.ASCII);
byte[] bytes = reader.ReadBytes((int)length);
Response.OutputStream.Write(bytes, 0, length);
reader.Close();
objStream.Close();
}
you need to use these additional namespaces in that page...
<pre lang="cs">using System.IO;
using System.Net;
using System.Text;
在您的主要aspx文件中有一个图像和一个按钮
In your main aspx file have an image and a button
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Image ID="Image1" runat="server" ImageUrl="" />
在按钮上单击事件
on the button click event
protected void Button1_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "~/image.aspx?image_path=http://www.a1indiaflowers.in/wp-content/uploads/2010/12/47-150x150.jpg";
}
在本示例中,您可以扩展到gridview行绑定事件.这将动态加载图像.但是正如Sandeep所说,您可以在本地拥有这些图像的缓存,并将该图像列表存储在数据库中.这样您就可以检查映像的可用性以及是否有本地负载.
要下载到本地,您可以在上面的示例中获得响应流,并使用文件流将其保存在服务器上.
This example you can extend to gridview row bound event. This loads the image dynamically. But as Sandeep said you can have a local cache of those images and have that image list in a database. So that you can check the image availability and if available load from local.
To download to local you can get the response stream in the above example and use a file stream to save it on the server..
//here the objStream is the response stream we got in the above example.
StreamReader reader = new StreamReader(objStream,Encoding.ASCII);
FileStream fStream = new FileStream("Test.jpg", FileMode.Create);
StreamWriter writer=new StreamWriter(fStream);
writer.Write(reader.ReadToEnd());
objStream.Close();
reader.Close();
writer.Close();
fStream.Close();
这篇关于从其他网站提取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文