Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Having a bit of trouble getting started on making a simple HTTP image browser. I prompt the user for a URL for an image, and then click a button and display the image in a picturebox. I'm used to writing console applications, and am brand new to the Windows Forms commands, which is why I'm looking for some help.

**In addition, but not necessary, is the inclusion of a status code of the image, as well as associated headers that are returned by googles web server, which are displayed in textboxes. Sorry if this is too vague, I am just completely lost, and anything would help. Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 13-Apr-15 20:16pm    
What could be your problem here? What have you tried so far?
—SA

1 solution

To get an image from HTTP, you need to download it. You don't even need to download it to temporary file (https://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename%28v=vs.110%29.aspx), as you can read the image to some stream.
Please see all the methods System.Net.WebClient.Download*:
https://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.110%29.aspx.

So, as you can see, not only you can download image to a temporary file, you can also download it to memory, to read the image directly from memory stream. However, this is not the best way.

Better yet, you can use the class System.Net.HttpWebRequest, get an HTTP response and open the response stream, to read the image from: https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28v=vs.110%29.aspx.

From the stream, you can read the image: https://msdn.microsoft.com/en-us/library/system.drawing.image.fromstream%28v=vs.110%29.aspx.

Finally, you can assign the image you read to the property PictureBox.Image: https://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.image%28v=vs.110%29.aspx.

—SA
 
Share this answer
 
Comments
Member 11604524 13-Apr-15 21:15pm    
Thanks! I'll give it a try
Sergey Alexandrovich Kryukov 13-Apr-15 21:38pm    
Please don't to accept the answer formally. This is all you really need.
In all cases, your follow-up questions will be welcome.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900