This project is read-only.

CameraProxy streaming to C# over URL

Oct 6, 2016 at 1:31 PM
Hi, This is a great project that brings cameras together.

I have installed the Camera Proxy on a computer on the network, and like to read the image over a web url to a Bitmap image, in a C# project.


Currently I do the following, which had work when I read it from an IP Camera directly , but like to read it from the CameraProxy instad, because of the grouping of the cameras.
        string sourceURL = "http://"+ ipToCall + ":44456/image/bin.cam";
        byte[] buffer = new byte[100000];
        int read, total = 0;
        // create HTTP request
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourceURL);
        // set login and password
        req.Credentials = new NetworkCredential("admin", "admin");
        // get response
        WebResponse resp = req.GetResponse();
        // get response stream
        Stream stream = resp.GetResponseStream();
        // read data from stream
        while ((read = stream.Read(buffer, total, 1000)) != 0)
        {
            total += read;
        }
        // get bitmap

        Bitmap bmp = (Bitmap)Bitmap.FromStream(
                      new MemoryStream(buffer, 0, total));

What must I do to be able to read the url of the CameraProxy to a stream, and save as a Bitmap image.
Thanks
Coordinator
Oct 6, 2016 at 2:39 PM
Edited Oct 6, 2016 at 2:43 PM
Hello.

There are a few things I notice about the code there. First, it would fail to handle any image over 100 KB in size because your buffer is a fixed size. Second, your URL is to the ".cam" page, which is html. Change the extension to .jpg to get an image instead. Third, I don't think that method of authentication will work. It expects the server to be capable of HTTP Basic Authentication or Digest Authentication, which if I recall CameraProxy is not. Instead, you can embed the credentials in the URL like this:
string sourceURL = "http://"+ ipToCall + ":44456/image/bin.jpg?rawauth=admin:admin";
If you want to simplifiy your code a little further, you can do this:
WebClient wc = new WebClient();
byte[] buffer = wc.DownloadData(sourceURL);
Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(buffer, 0, buffer.Length));
Or perhaps this instead:
        string sourceURL = "http://"+ ipToCall + ":44456/image/bin.jpg?rawauth=admin:admin";
        // create HTTP request
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourceURL);
        // get response
        WebResponse resp = req.GetResponse();
        // get response stream
        Stream stream = resp.GetResponseStream();
        // get bitmap
        Bitmap bmp = (Bitmap)Bitmap.FromStream(stream);
Coordinator
Oct 6, 2016 at 2:42 PM
Oh, and one more thing. When you are done with each Bitmap, you should call Dispose() on it. Otherwise your program may leak resources and eventually crash.
Oct 7, 2016 at 6:35 AM
Thank you,

It is now working great.

--
Floris Prinsloo
Email: [email removed]
Cell: 0761385708