2020年8月31日 星期一

vb.net 圖片下載 [Download Image]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Imports System.Net
Imports System.IO

    Public Function webDownloadImage(ByVal Url As String, Optional ByVal saveFile As Boolean = False, Optional ByVal location As String = "C:\") As Image
        Dim webClient As New WebClient
        Dim bytes() As Byte = webClient.DownloadData(Url)
        Dim stream As New MemoryStream(bytes)

        If saveFile Then My.Computer.FileSystem.WriteAllBytes(location, bytes, False)

        Return New System.Drawing.Bitmap(stream)
    End Function





1
2
3
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PictureBox1.Image = webDownloadImage("https://www.google.com.tw/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png")
    End Sub

沒有留言:

張貼留言