Click here to Skip to main content
15,891,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys, I have a network camera. Now I have a website to monitor the images from that camera. I want to know how to get the image from the camera to a folder on my server.

The URL is like follows: http://{IPAddress}/images/nbEyeEnc_0_CAMERA/QVGA/campic.jpg


When I tried copying it with system.io.copy I got the following exception:
URI formats are not supported.

Please help me guys.
Posted
Updated 13-May-10 22:55pm
v3

C#
using System.Net;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;

string url = "http://www.codeproject.com/App_Themes/Std/Img/logo225x90.gif";
        Bitmap b;
        Uri uri = new Uri(url);
        WebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
        using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
        {
            using (Stream stream = webResponse.GetResponseStream())
            {
                System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
                img.Save(Server.MapPath(Guid.NewGuid().ToString() + ".jpg"));
                img.Dispose();
            }
        }
 
Share this answer
 
v2
 
Share this answer
 
Comments
kornakar 17-May-10 6:24am    
I don't understand why my answer was voted as 1. It works perfectly. The other answer voted 5 loads a GIF file and saves it as JPG with random name :(
Unforgiv3n 18-May-10 2:43am    
i get the following exception?

The remote server returned an error: (407) Proxy Authentication Required.

at the line :

WebResponse myResp = myReq.GetResponse();

if you can solve it i will give you 20 out of 5 :D
kornakar 18-May-10 7:24am    
webRequest.Proxy = WebRequest.DefaultWebProxy

Now waiting for my 20 :P

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