I want to load an image into a PictureBox
. This is the image I want to load: http://www.gravatar.com/avatar/6810d91caff032b202c50701dd3af745?d=identicon&r=PG
How do I do this?
I want to load an image into a PictureBox
. This is the image I want to load: http://www.gravatar.com/avatar/6810d91caff032b202c50701dd3af745?d=identicon&r=PG
How do I do this?
Try this:
If you are trying to load the image at your form_load, it's a better idea to use the code
not only loading from web but also no lag in your form loading.
The inbuilt PictureBox.Load(string URL) Method "sets the ImageLocation to the specified URL and displays the image indicated." (Since .NetFramework 2)
Here's the solution I use. I can't remember why I couldn't just use the PictureBox.Load methods. I'm pretty sure it's because I wanted to properly scale & center the downloaded image into the PictureBox control. If I recall, all the scaling options on PictureBox either stretch the image, or will resize the PictureBox to fit the image. I wanted a properly scaled and centered image in the size I set for PictureBox.
Now, I just need to make a async version...
Here's my methods:
Here's the required includes. (Some might be needed by other code, but including all to be safe)
How I generally use it: