Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using AForge;
  9. using AForge.Video;
  10. using AForge.Video.DirectShow;
  11.  
  12. namespace WebCamTest
  13. {
  14.     public partial class _Default : System.Web.UI.Page
  15.     {
  16.         VideoCaptureDevice videoSource;
  17.  
  18.         protected void Page_Load(object sender, EventArgs e)
  19.         {
  20.             // enumerate video devices
  21.             var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
  22.  
  23.             // create video source
  24.             videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
  25.            
  26.             // set NewFrame event handler
  27.             videoSource.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
  28.  
  29.             videoSource.VideoResolution = videoSource.VideoCapabilities.First();
  30.  
  31.             // start the video source
  32.             videoSource.Start();
  33.             videoSource.WaitForStop();
  34.         }
  35.  
  36.         protected void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
  37.         {
  38.             videoSource.SignalToStop();
  39.  
  40.             Bitmap bitmap = eventArgs.Frame;
  41.            
  42.             Page.Response.Clear();
  43.             Page.Response.ContentType = "image/jpeg";
  44.            
  45.             bitmap.Save(Page.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement