I found this article by Laurent Kempé while searching for something to playaround with.This sample application utilizes the System.Net namespace to implement a port to C# of the C++ ATL Web Service. .NET COM Interop is used to import the said component to the C# project.
You can get read the complete information about this project on CodeProject.
A sample code is listed below.
[WebMethod]public byte[] GrabFrame( short nQuality ){//Write to the EventLog the IP and Host namestring addr = HttpContext.Current.Request.UserHostAddress.Trim();string name;IPHostEntry host = null;try{host = System.Net.Dns.GetHostByAddress( addr );if ( host != null ){name = host.HostName;for( int i = 0; i < host.Aliases.Length; i++ )name += "*" + host.Aliases[i];eventLog.WriteEntry( addr + " : " + name );}else{name = "ERROR";eventLog.WriteEntry( name );}}catch( System.Exception error ){// process the error error.Message}//Shoot a picture from my webcamCAMSERVERLib.Camera cam = new CAMSERVERLib.CameraClass();byte[] picture = (byte[])cam.GrabFrame( nQuality );//Increments Performance CounterperformanceCounterShoot.Increment();//Add the hourMemoryStream ms = new MemoryStream( picture );Bitmap bmp = new Bitmap( ms );Graphics g = Graphics.FromImage( bmp );string strDate = DateTime.Now.ToLongDateString() + " - " + DateTime.Now.ToLongTimeString(); g.DrawString( strDate,new Font( FontFamily.GenericSansSerif, 10 ),new SolidBrush( Color.Black ), new RectangleF( 1,1,320,240 ) );g.DrawString( strDate,new Font( FontFamily.GenericSansSerif, 10 ),new SolidBrush( Color.White ), new RectangleF( 0,0,320,240 ) );MemoryStream ms2 = new MemoryStream();//Get codecsImageCodecInfo[] icf = ImageCodecInfo.GetImageEncoders();EncoderParameters encps = new EncoderParameters( 1 );EncoderParameter encp = new EncoderParameter( Encoder.Quality, (long) nQuality );//Set qualityencps.Param[0] = encp;bmp.Save( ms2, icf[1], encps );ms2.Close();return ms2.ToArray();}
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.