从wewbsite获取图像 [英] Getting image from wewbsite

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

问题描述

有人知道如何从加载到

webbrowser控件中的网页中提取图像,并将其保存到文件中或将其保存在数据库中吗?


干杯,

Johnny J.

解决方案




" ; Johnny J?rgensen" < jo ** @ altcom.sewrote in message

news:Ot ************** @ TK2MSFTNGP02.phx.gbl ...
< blockquote class =post_quotes>
有没有人知道如何从加载到

a webbrowser控件中的网页中提取图像,并将其保存到文件中或将其保存在数据库中?


干杯,

Johnny J.



您需要像在图片中一样阅读图片在网页上阅读....首先,

打开网页并解析图片的路径...然后,您可以使用

以下代码获取图像的字节数组并存储到数据库中的文件或

数据列。


//开始C#

string url =

@" http://www.co.merced.ca.us/CountyWeb/images/GeneralActive.gif" ;;

HttpWebRequest request =

(HttpWebRequest)WebRequest.Create(url);

HttpWebResponse response =

(HttpWebResponse)request.GetResponse();


byte [] bytes;

using(Stream stream = response.GetResponseStream()){

bytes = new byte [response.ContentLength];

stream.Read(bytes,0,bytes.Length);

}


//现在我们有一个字节数组要做希望,保存到文件

现在。

FileStream fs = File.Create(@C:\ GeneneralActive.gif);

fs.Write(bytes,0,bytes.Length);

fs.Close();


//或写入数据库。

//要执行此操作,请创建一个IMAGE(SQL Server)列,然后将字节数组复制到DataRow的字段中。图像列

//映射到DataRow中DataColumn中的字节数组。


//结束C#


在更新版本的.Net

框架中可能会有更简单或更好的方式,但是...... :)

HTH,

Mythran


Johny,


一旦你知道它的网址,就可以下载它使用


DownloadFile
http://msdn2.microsoft.com/en-us/lib...le(VS.71).aspx


要在webbrowser中获取它,你需要大量的mshtml

http://support.microsoft.com/kb/311284

Cor


" Johnny J?rgensen" < jo ** @ altcom.seschrieb:


有没有人知道如何从加载到的网页中提取图像

a webbrowser control并将其保存到文件或将其保存在数据库中?



''My.Computer.Network.DownloadFile''

''System.Net.WebClient.DownloadFile''


您可以将二进制数据作为BLOB存储在数据库中。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http://dotnet.mvps.org/dotnet/faqs/ >


Does anybody know how you can extract an image fron a webpage loaded into a
webbrowser control and either save it to file OR save it in a database?

Cheers,
Johnny J.

解决方案



"Johnny J?rgensen" <jo**@altcom.sewrote in message
news:Ot**************@TK2MSFTNGP02.phx.gbl...

Does anybody know how you can extract an image fron a webpage loaded into
a webbrowser control and either save it to file OR save it in a database?

Cheers,
Johnny J.

You need to read in the image as if you were reading in a webpage....first,
open the web page and parse the path to the image...then, you can use the
following code to get the byte-array of the image and store to a file or
data column in a database.

// BEGIN C#

string url =
@"http://www.co.merced.ca.us/CountyWeb/images/GeneralActive.gif";
HttpWebRequest request =
(HttpWebRequest) WebRequest.Create(url);
HttpWebResponse response =
(HttpWebResponse) request.GetResponse();

byte[] bytes;
using (Stream stream = response.GetResponseStream()) {
bytes = new byte[response.ContentLength];
stream.Read(bytes, 0, bytes.Length);
}

// Now we have a byte array to do as we wish, saving to a file
now.
FileStream fs = File.Create(@"C:\GeneralActive.gif");
fs.Write(bytes, 0, bytes.Length);
fs.Close();

// OR write to a database.
// To do this, create an IMAGE (SQL Server) column and just copy
// the byte array into the field for a DataRow. An Image column
// maps to a byte-array in a DataColumn in a DataRow.

// END C#

There may be an easier or better way in a more recent version of the .Net
Framework though... :)
HTH,
Mythran


Johny,

As soon as you know its url location you can download it using

DownloadFile
http://msdn2.microsoft.com/en-us/lib...le(VS.71).aspx

To get that in a webbrowser you mostly needs a lot of mshtml

http://support.microsoft.com/kb/311284

Cor


"Johnny J?rgensen" <jo**@altcom.seschrieb:

Does anybody know how you can extract an image fron a webpage loaded into
a webbrowser control and either save it to file OR save it in a database?

''My.Computer.Network.DownloadFile''
''System.Net.WebClient.DownloadFile''

You can store the binary data in the database as a BLOB.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


这篇关于从wewbsite获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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