<

How to load images from URI into a .NET image object

Published on
8,250 Points
5,150 Views
1 Endorsement
Last Modified:
In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it.

The first step, was to retrieve the image from camera into Image object. So that it can be displayed or do some processing on it.

Some of the IP cameras have an interface to acquire images or streams. One of the easiest interfaces is giving some steel JPEG images. For example via a simple HTTP request (e.g. http://webcam.mmhk.cz/axis-cgi/jpg/image.cgi) we have an JPEG image.

Here is code snippet to acquire an image from a URI and display in a PictureBox.
 
//uri resource
Uri uri = new Uri("the uri goes here, e.g. http://webcam.mmhk.cz/axis-cgi/jpg/image.cgi");

//create a stream using a http web request
System.IO.Stream s = 
  System.Net.HttpWebRequest.Create(uri)
  .GetResponse().GetResponseStream();

//create an image object from stream
Image img = Image.FromStream(s);

//display image in a picture box
this.pictureBox1.Image = img;

Open in new window

Simple and easy!

    Previously published in my blog: blog.mrt-web.com
1
Enjoy this complimentary article view.

Get unlimited access to our entire library of technical procedures, guides, and tutorials written by certified industry professionals.

Get 7 days free
Click here to view the full article

Using this article for work? Experts Exchange can benefit your whole team.

Learn More
COLLABORATE WITH CERTIFIED PROFESSIONALS
Experts Exchange is a tech solutions provider where users receive personalized tech help from vetted certified professionals. These industry professionals also write and publish relevant articles on our site.
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Learn from the best.