Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click
Dim strUrl As String = TextBox1.Text If strUrl.Length = 0 Then MsgBox("画像までのURLを入力してください") Exit Sub End If
Dim WebC As WebClient = New WebClient Dim MyStream As Stream = WebC.OpenRead(strUrl)
Dim MyBitmap As Bitmap Dim Gr As Graphics
MyBitmap = New Bitmap(MyStream) MyStream.Close()
Dim intWidth As Integer = MyBitmap.Width / 2 Dim intHeight As Integer = MyBitmap.Height / 2 MyBitmap2 = New Bitmap(MyBitmap, intWidth, intHeight)
'描画先のピクチャーボックスに、 'グラフィックオブジェクトを作成() Gr = PictureBox1.CreateGraphics()
'画像を表示 Gr.DrawImage(MyBitmap2, 0, 0)
'グラフィックオブジェクト解放 Gr.Dispose() MyBitmap.Dispose()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) _ Handles PictureBox1.Paint
Try If Not IsNothing(MyBitmap2) Then
'画像を表示 e.Graphics.DrawImage(MyBitmap2, 0, 0) End If
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Closing(ByVal sender As Object, _ ByVal e As System.ComponentModel.CancelEventArgs) _ Handles MyBase.Closing MyBitmap2.Dispose() End Sub