Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Drawing.Imaging;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using System.Diagnostics;
  11. using System.IO;
  12. using System.Net;
  13.  
  14. using AForge;
  15. using AForge.Video;
  16. using AForge.Controls;
  17. using AForge.Video.DirectShow;
  18.  
  19. namespace AddPanel
  20. {
  21. public partial class test : UserControl
  22. {
  23. public string IPadd { get; set; }
  24. public string usrID { get; set; }
  25. public string pswd { get; set; }
  26. public string filename { get; set; }
  27. public FileStream ws { get; set; }
  28.  
  29. public test()
  30. {
  31. InitializeComponent();
  32. }
  33.  
  34. public test(string Ip, string Id, string Pass, string file, FileStream stream)
  35. {
  36. InitializeComponent();
  37.  
  38. IPadd = Ip;
  39. usrID = Id;
  40. pswd = Pass;
  41. filename = file;
  42. ws = stream;
  43.  
  44. JPEGStream jpegSource1 = new JPEGStream("http://" + IPadd + "/jpg/image.jpg?resolution=320x240");
  45. jpegSource1.Login = usrID;
  46. jpegSource1.Password = pswd;
  47. jpegSource1.NewFrame += new NewFrameEventHandler(jpegSource1_NewFrame);
  48. jpegSource1.VideoSourceError += new VideoSourceErrorEventHandler(jpegSource1_VideoSourceError);
  49. jpegSource1.VideoSourceError += new VideoSourceErrorEventHandler(jpegSource1_VideoSourceError);
  50. Player1.VideoSource = jpegSource1;
  51.  
  52. }
  53.  
  54. void jpegSource1_NewFrame(object sender, NewFrameEventArgs eventArgs)
  55. {
  56. Bitmap image = new Bitmap(eventArgs.Frame, 320, 240);
  57.  
  58. image.Save(ws, System.Drawing.Imaging.ImageFormat.Bmp);
  59. }
  60.  
  61. void jpegSource1_VideoSourceError(object sender, VideoSourceErrorEventArgs eventArgs)
  62. {
  63. //Error handler
  64. Debug.WriteLine(eventArgs.Description);
  65.  
  66. Bitmap ErPic = new Bitmap(320, 240);
  67. using (var g = Graphics.FromImage(ErPic))
  68. {
  69. using (var arialFontLarge = new Font("Arial", 15))
  70. {
  71. g.DrawString("Camera Offline", arialFontLarge, Brushes.White, 75, 100);
  72. }
  73.  
  74. }
  75. ErPic.Save(ws, ImageFormat.Bmp);
  76. }
  77.  
  78. private void StartBut_Click(object sender, EventArgs e)
  79. {
  80. Player1.VideoSource.Start();
  81. }
  82.  
  83. private void StopBut_Click(object sender, EventArgs e)
  84. {
  85. Player1.VideoSource.Stop();
  86. ws.Close();
  87. }
  88. }
  89. }
  90.  
  91. Player1.VideoSource.Start();
  92.  
  93. Player1.VideoSource = jpegSource1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement