This will definitely work for you, sorry for the delay... Make sure you Import System.IO namespace as well... When you use the Image.FromFile(strFileName) method to create the Image, the method locks the file until you release the Image. Instead we can use FileStream
to accomplish this task.
For Each subitem As JObject In item.Values
Dim newPictureBox As New Button
Dim Client As New WebClient
strID = "http://graph.facebook.com/" & subitem("id").ToString.Replace("""", "") & "/picture?width=126&height=114"
strName = subitem("name").ToString
Client.DownloadFile(strID, "C:\wamp\www\img\" & subitem("id").ToString.Replace("""", "") & ".jpg")
Client.Dispose()
Dim bmp As Bitmap
Dim strPath As String = "C:\wamp\www\img\" & subitem("id").ToString.Replace("""", "") & ".jpg"
Using fs As New FileStream(strPath, FileMode.Open, FileAccess.Read)
Using b As New Bitmap(fs)
bmp = New Bitmap(b.Width, b.Height, b.PixelFormat)
Using g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(b, Point.Empty)
g.Flush()
End Using
End Using
End Using
newPictureBox.BackgroundImage = bmp
newPictureBox.Tag = subitem("id").ToString.Replace("""", "")
newPictureBox.Name = "img" & intX
newPictureBox.Width = bmp.Width.ToString()
newPictureBox.Height = bmp.Height.ToString()
FlowLayoutPanel1.Controls.Add(newPictureBox)
AddHandler newPictureBox.Click, AddressOf newPictureBox_Click
intX += 1
imgDir.Add(strName, subitem("id").ToString.Replace("""", ""))
Next