Ahoj.
Jak lze ve VB6 co nejjednodušeji stáhnout obrázek z netu na disk ?
Fórum › Visual Basic
Jak stáhnout obrázek z netu

Co jsi nasel googlem?
Vetsinou to funguje tak, ze se pouziva neco jako curl. Samozrejme o VB nic nevim, takze netusim, jak se to tam jmenuje. Ve VB mozna pujde otevrit browser.
Co jsem nasel ja googlem?
Dim Client as new WebClient
Client.DownloadFile(Source, Destination)
Client.Dispose
---
Private Shared Sub DownloadImage(url As String, saveFilename As String)
Dim httpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim httpWebResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
If (httpWebResponse.StatusCode <> HttpStatusCode.OK AndAlso httpWebResponse.StatusCode <> HttpStatusCode.Moved AndAlso httpWebResponse.StatusCode <> HttpStatusCode.Redirect) OrElse Not httpWebResponse.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase) Then
Return
End If
Using stream = httpWebResponse.GetResponseStream()
Using fileStream = File.OpenWrite(saveFilename)
Dim bytes = New Byte(4095) {}
Dim read = 0
Do
If stream Is Nothing Then
Continue Do
End If
read = stream.Read(bytes, 0, bytes.Length)
fileStream.Write(bytes, 0, read)
Loop While read <> 0
End Using
End Using
End Sub
----
https://www.digitalcoding.com/…rom-URL.html
''' <summary>
02
''' Function to download Image from website
03
''' </summary>
04
''' <param name="_URL">URL address to download image</param>
05
''' <returns>Image</returns>
06
Public Function DownloadImage(ByVal _URL As String) As Image
07
Dim _tmpImage As Image = Nothing
08
09
Try
10
' Open a connection
11
Dim _HttpWebRequest As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(_URL), System.Net.HttpWebRequest)
12
13
_HttpWebRequest.AllowWriteStreamBuffering = True
14
15
' You can also specify additional header values like the user agent or the referer: (Optional)
16
_HttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
17
_HttpWebRequest.Referer = "http://www.google.com/"
18
19
' set timeout for 20 seconds (Optional)
20
_HttpWebRequest.Timeout = 20000
21
22
' Request response:
23
Dim _WebResponse As System.Net.WebResponse = _HttpWebRequest.GetResponse()
24
25
' Open data stream:
26
Dim _WebStream As System.IO.Stream = _WebResponse.GetResponseStream()
27
28
' convert webstream to image
29
_tmpImage = Image.FromStream(_WebStream)
30
31
' Cleanup
32
_WebResponse.Close()
33
_WebResponse.Close()
34
Catch _Exception As Exception
35
' Error
36
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString())
37
Return Nothing
38
End Try
39
40
Return _tmpImage
41
End Function
' Download web image
02
Dim _Image As Image = Nothing
03
_Image = DownloadImage("http://www.youdomain.com/sample-image.jpg")
04
05
' check for valid image
06
If _Image IsNot Nothing Then
07
' show image in picturebox
08
pictureBox1.Image = _Image
09
10
' lets save image to disk
11
_Image.Save("C:\\sample-image.jpg")
12
End If
Nakonec jsem řešení našel zde:
https://stackoverflow.com/…-vb6/1979417#…
Zkoušel jsem první dva příklady. Oba jsou funkční, ale soubor je vždy uložen do:
c:\Users\Lubos\AppData\Local\VirtualStore\
Dá se to nějak napravit ?

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 13 hostů
Podobná vlákna
Jak toto stáhnout ? — založil davidus
Knihovny, jak opravit nebo stáhnout? — založil Lukáš
Jak stahnout PDF soubor web prohlížeče — založil remmidemmi
Jak stahnout malej txt soubor z PC v lokalni siti prostrednictvim WI… — založil VladislavK
Jak oříznout obrázek — založil fswolf
Moderátoři diskuze