private void PoolMethod() { try { if (!this.httpListener.IsListening) { return; } HttpListenerContext context = this.httpListener.GetContext(); HttpListenerResponse response = context.Response; response.ContentType = "multipart/x-mixed-replace; boundary=--myboundary"; Stream responseStream = response.OutputStream; MessageImg arg = new MessageImg(); for (; ;) { if (requestToStopTheThread) { break; } if (this.OnGetImage == null) { continue; } // Get image. this.OnGetImage(this, arg); MemoryStream imageStream = new MemoryStream(); JpegUtils.SaveJPG100(arg.Image, imageStream); byte[] headerBytes = asciiEncodeing.GetBytes("\r\n--myboundary\r\nContent-Type: image/jpeg\r\nContent-Length:" + imageStream.Length + "\r\n\r\n"); MemoryStream headerStream = new System.IO.MemoryStream(headerBytes); headerStream.WriteTo(responseStream); imageStream.WriteTo(responseStream); responseStream.Flush(); this.FrameCount++; System.Threading.Thread.Sleep(20); } } catch (Exception exception) { this.Stop(); } this.Stop(); }
private void PoolMethod() { try { if (!this.httpListener.IsListening) { return; } HttpListenerContext context = this.httpListener.GetContext(); HttpListenerResponse response = context.Response; response.ContentType = "multipart/x-mixed-replace; boundary=--myboundary"; Stream responseStream = response.OutputStream; MessageImg arg = new MessageImg(); for (; ; ) { if (requestToStopTheThread) { break; } if (this.OnGetImage == null) { continue; } // Get image. this.OnGetImage(this, arg); MemoryStream imageStream = new MemoryStream(); JpegUtils.SaveJPG100(arg.Image, imageStream); byte[] headerBytes = asciiEncodeing.GetBytes("\r\n--myboundary\r\nContent-Type: image/jpeg\r\nContent-Length:" + imageStream.Length + "\r\n\r\n"); MemoryStream headerStream = new System.IO.MemoryStream(headerBytes); headerStream.WriteTo(responseStream); imageStream.WriteTo(responseStream); responseStream.Flush(); this.FrameCount++; System.Threading.Thread.Sleep(20); } } catch (Exception exception) { this.Stop(); } this.Stop(); }
private void server_GetImage(object sender, MessageImg e) { #if USE_EMGUCV Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> image = this.capture.QueryFrame(); string dateAndTime = DateTime.Now.ToString("yyyy.MM.dd/HH:mm:ss.fff", System.Globalization.DateTimeFormatInfo.InvariantInfo); image.Draw(dateAndTime, ref f, new Point(10, 30), new Emgu.CV.Structure.Bgr(0, 255, 0)); e.Image = image.Bitmap; #elif NOT_USE_EMGUCV e.Image = GetImage(); #endif }