有可能以programmaticaly方式保存给定URL的图形格式吗? [英] Is is possible to programmaticaly save a graphic forma given URL?

查看:64
本文介绍了有可能以programmaticaly方式保存给定URL的图形格式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧..也许我正在尝试错误的做法。如果给出了图形的URL,我想要将该图形保存到本地文件中。下面的方法获得了

响应,但我无法弄清楚如何将其保存到文件中。在这个

实例中,创建了一个文件,但它只包含文本

" System.Io.StreamReader"我也尝试过writer.write(reader.ReadToEnd),

但该文件仍然没有显示任何内容。

Dim URL As String = GraphicURL


Dim request As WebRequest = WebRequest.Create(URL)


Dim response As WebResponse = request.GetResponse()


Dim reader As StreamReader = New


StreamReader(response.GetResponseStream())

Dim writer As StreamWriter = New StreamWriter(" C:\\ \\ temp \"& GraphicKey&

" .jpg")


writer.Write(读者)

writer.Close()


reader.Close()


response.Close()

Stacey Levine

Ok.. Maybe I am trying the wrong approach. If given a URL to a graphic, I
want to save that graphic to a local file. The approach below gets the
response, but I can''t quite figure out how to save it to a file. In this
instance, a file gets created but it only contains the text
"System.Io.StreamReader" I have also tried writer.write(reader.ReadToEnd),
but the file still displays nothing.
Dim URL As String = GraphicURL

Dim request As WebRequest = WebRequest.Create(URL)

Dim response As WebResponse = request.GetResponse()

Dim reader As StreamReader = New

StreamReader(response.GetResponseStream())

Dim writer As StreamWriter = New StreamWriter("C:\temp\" & GraphicKey &
".jpg")

writer.Write(reader)

writer.Close()

reader.Close()

response.Close()
Stacey Levine

推荐答案

是的,你正在写读者,而不是写读者的内容

阅读: )尝试写reader.readtoend(或其他)。

Stacey Levine < ST **** @ newsgroup.nospam>在消息中写道

news:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
Yes, you are writing the reader, rather than writing what the reader is
reading :) Try writing reader.readtoend (or something).
"Stacey Levine" <st****@newsgroup.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
好的。也许我正在尝试错误的方法。如果给出了图形的URL,我想将该图形保存到本地文件中。下面的方法得到了
响应,但我无法弄清楚如何将其保存到文件中。在这个实例中,创建了一个文件,但它只包含文本
System.Io.StreamReader。我也尝试过writer.write(reader.ReadToEnd),
但文件仍然没有显示。

Dim URL As String = GraphicURL

Dim request As WebRequest = WebRequest.Create(URL)

昏暗的响应As WebResponse = request.GetResponse()

Dim reader As StreamReader = New

StreamReader(响应) .GetResponseStream())

Dim writer As StreamWriter = New StreamWriter(" C:\ temp \"& GraphicKey&
" .jpg")
writer.Write(读者)

writer.Close()

reader.Close()

response.Close()

Stacey Levine
Ok.. Maybe I am trying the wrong approach. If given a URL to a graphic, I
want to save that graphic to a local file. The approach below gets the
response, but I can''t quite figure out how to save it to a file. In this
instance, a file gets created but it only contains the text
"System.Io.StreamReader" I have also tried writer.write(reader.ReadToEnd),
but the file still displays nothing.
Dim URL As String = GraphicURL

Dim request As WebRequest = WebRequest.Create(URL)

Dim response As WebResponse = request.GetResponse()

Dim reader As StreamReader = New

StreamReader(response.GetResponseStream())

Dim writer As StreamWriter = New StreamWriter("C:\temp\" & GraphicKey &
".jpg")

writer.Write(reader)

writer.Close()

reader.Close()

response.Close()
Stacey Levine



我确实尝试过writer.write(reader.ReadToEnd),而且文件还有更多数据..它

都是十六进制..但它仍然不会打开图片。我不确定我是否错过了写作的东西。

Robin Tucker <编号********** @ reallyidont.com>写在

消息新闻:da ******************* @ news.demon.co.uk ...
I did try writer.write(reader.ReadToEnd), and the file has more data.. it
is all hex.. but it still won''t open as a picture. I am not sure if I missed
writing something.
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:da*******************@news.demon.co.uk...
是的,你正在写读者,而不是写作读者阅读的内容:)尝试写一下reader.readtoend(或其他东西)。

" Stacey Levine" < ST **** @ newsgroup.nospam>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
Yes, you are writing the reader, rather than writing what the reader is
reading :) Try writing reader.readtoend (or something).
"Stacey Levine" <st****@newsgroup.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
好的..也许我是尝试错误的方法。如果给出了图形的URL,我想将该图形保存到本地文件中。下面的方法得到了
响应,但我无法弄清楚如何将其保存到文件中。在这个实例中,创建了一个文件,但它只包含文本
System.Io.StreamReader。我也试过了
writer.write(reader.ReadToEnd),但文件仍然没有显示。

Dim URL As String = GraphicURL

Dim request As WebRequest = WebRequest.Create(URL)

昏暗的响应As WebResponse = request.GetResponse()

Dim reader As StreamReader = New

StreamReader(响应) .GetResponseStream())

Dim writer As StreamWriter = New StreamWriter(" C:\ temp \"& GraphicKey&
" .jpg")
writer.Write(读者)

writer.Close()

reader.Close()

response.Close()

Stacey Levine
Ok.. Maybe I am trying the wrong approach. If given a URL to a graphic, I
want to save that graphic to a local file. The approach below gets the
response, but I can''t quite figure out how to save it to a file. In this
instance, a file gets created but it only contains the text
"System.Io.StreamReader" I have also tried
writer.write(reader.ReadToEnd), but the file still displays nothing.
Dim URL As String = GraphicURL

Dim request As WebRequest = WebRequest.Create(URL)

Dim response As WebResponse = request.GetResponse()

Dim reader As StreamReader = New

StreamReader(response.GetResponseStream())

Dim writer As StreamWriter = New StreamWriter("C:\temp\" & GraphicKey &
".jpg")

writer.Write(reader)

writer.Close()

reader.Close()

response.Close()
Stacey Levine




另一个奇怪的位...当我保存文件使用reader.ReadToEnd ..

文件有1302个字节。

如果我右键单击图像保存,它有2257个字节。


非常非常奇怪


" Stacey Levine" < ST **** @ newsgroup.nospam>在消息中写道

news:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
One other wierd bit.. when I save the file using the reader.ReadToEnd ..
the file has 1302 bytes.
If I right click the image and save it, it has 2257 bytes.

very very wierd

"Stacey Levine" <st****@newsgroup.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
好的。也许我正在尝试错误的方法。如果给出了图形的URL,我想将该图形保存到本地文件中。下面的方法得到了
响应,但我无法弄清楚如何将其保存到文件中。在这个实例中,创建了一个文件,但它只包含文本
System.Io.StreamReader。我也尝试过writer.write(reader.ReadToEnd),
但文件仍然没有显示。

Dim URL As String = GraphicURL

Dim request As WebRequest = WebRequest.Create(URL)

昏暗的响应As WebResponse = request.GetResponse()

Dim reader As StreamReader = New

StreamReader(响应) .GetResponseStream())

Dim writer As StreamWriter = New StreamWriter(" C:\ temp \"& GraphicKey&
" .jpg")
writer.Write(读者)

writer.Close()

reader.Close()

response.Close()

Stacey Levine
Ok.. Maybe I am trying the wrong approach. If given a URL to a graphic, I
want to save that graphic to a local file. The approach below gets the
response, but I can''t quite figure out how to save it to a file. In this
instance, a file gets created but it only contains the text
"System.Io.StreamReader" I have also tried writer.write(reader.ReadToEnd),
but the file still displays nothing.
Dim URL As String = GraphicURL

Dim request As WebRequest = WebRequest.Create(URL)

Dim response As WebResponse = request.GetResponse()

Dim reader As StreamReader = New

StreamReader(response.GetResponseStream())

Dim writer As StreamWriter = New StreamWriter("C:\temp\" & GraphicKey &
".jpg")

writer.Write(reader)

writer.Close()

reader.Close()

response.Close()
Stacey Levine



这篇关于有可能以programmaticaly方式保存给定URL的图形格式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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