Guest User

Untitled

a guest
Apr 6th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. Uri geturi = new Uri(_cgi);
  2. //Solicita um comando CGI para câmera FOSCAM
  3. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(geturi);
  4. byte[] imgByte = null;
  5. //Pega a Resposta do comando CGI, neste comando uma imagem.
  6. using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
  7. {
  8. if (response != null)
  9. {
  10. using (BinaryReader reader = new BinaryReader(response.GetResponseStream()))
  11. {
  12. imgByte = reader.ReadBytes(1 * 640 * 480 * 10);
  13. }
  14. }
  15. }
  16.  
  17. Uri geturi = new Uri(_cgi);
  18. string username = "admin";
  19. string password = "realdrive17";
  20.  
  21. //Seta as credenciais
  22. NetworkCredential cred = new NetworkCredential(username, password);
  23. CredentialCache cache = new CredentialCache();
  24. cache.Add(geturi, "Basic", cred);
  25.  
  26. //Solicita um comando CGI para câmera FOSCAM
  27. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(geturi);
  28. request.PreAuthenticate = true;
  29. request.Credentials = cache;
  30. byte[] imgByte = null;
  31.  
  32. //Pega a Resposta do comando CGI, neste comando uma imagem.
  33. using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
  34. {
  35. if (response != null)
  36. {
  37. using (BinaryReader reader = new BinaryReader(response.GetResponseStream()))
  38. {
  39. imgByte = reader.ReadBytes(1 * 1024 * 1024 * 10);
  40. //Converte os Bytes para um bitmap.
  41. if (BytesToBitmap(imgByte) != null)
  42. {
  43. RunOnUiThread(() =>
  44. {
  45. _image.SetImageBitmap(BytesToBitmap(imgByte));
  46. });
  47. return true;
  48. }
  49. }
  50. return false;
  51. }
  52. return false;
  53. }
Add Comment
Please, Sign In to add comment