Adding GetImage()

Nov 29, 2009 at 10:18 AM
Edited Nov 29, 2009 at 10:23 AM
     Hi,  here it.s the snippet to add getimage function, returns a bmp, how can be adapted to the library?
   public System.Drawing.Image GetImage(string rovioUsername, string rovioPassword, string rovioIPAddress)
        {
            System.Drawing.Image bmp = null;
                Uri URiL = new Uri(rovioIPAddress + "/Jpeg/CamImg000.jpg");
                string URL = rovioIPAddress + "/Jpeg/CamImg000.jpg";
                //Consola.WriteLine("Adquiriendo imagen JPEG\r\n");
                try
                {
                    StringBuilder sb = new StringBuilder();
                    byte[] buf = new byte[8192];
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
                    NetworkCredential myCred = new NetworkCredential(rovioUsername, rovioPassword);
                    CredentialCache MyCrendentialCache = new CredentialCache();
                    MyCrendentialCache.Add(URiL, "Basic", myCred);
                    request.Credentials = MyCrendentialCache;
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Stream resStream = response.GetResponseStream();
                    bmp = Bitmap.FromStream(resStream);

                }
                catch (WebException ex)
                {

                    //Consola.WriteLine("Error de red: " + ex + "\r\n");

                }
                catch (Exception ex)
                {
                    //Consola.WriteLine("Error general: " + ex + "\r\n");

                }
                return bmp;
        }
To get the image it.s simple..something like this:
RovioLib.RovioImage pp = new RovioLib.RovioImage();
this.pictureBox1.Image = pp.GetImage(usr, pas, adr);