private void ProcessMessages(string msg) { if (msg.StartsWith("Msg")) { MessageBox.Show(msg.Substring(3, msg.Length - 3), "Messasge", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } else if (msg == "Live") { camera = new WebCam(); if (!camera.IsConnected()) { camera.Connect(); cameraWorker.RunWorkerAsync(); } else { cameraWorker.CancelAsync(); } } else if (msg == "ScreenCap") { ScreenCap(true); } }
/// <summary> /// Captures an image using webcam. (Based on metricam library) /// </summary> /// <returns>Image object as captured</returns> static Image CaptureImage() { WebCam camera = new WebCam(); camera.Connect(); Image image = camera.GetBitmap(); camera.Disconnect(); return(image); }
private void button1_Click(object sender, EventArgs e) { if (!camera.IsConnected()) { camera.Connect(); camera.Update(); MemoryStream ms = new MemoryStream(); camera.CalcBitmap().Save(ms, ImageFormat.Bmp); byte[] bitmapData = ms.ToArray(); MemoryStream stream = new MemoryStream(bitmapData); pictureBox1.Image = new Bitmap(stream); } else { Application.Exit(); } }