/ Published in: C#
If you wish to make your home, office or warehouse more secure, taking frame captures can be a very useful solution for you. And I can tell you this because I’ve already implemented this function at my office. Now I am sharing the prewritten source code with you for such a solution.
What will you need for this function?
• A Visual C# WPF Application created in Visual Studio
• The VoIPSDK.dll added to the references. (It can be found on the website where I found the code: www.camera-sdk.com/)
The first part of the code under MainForm.cs is the code for the frame capturing program itself. It contains all the details you need to implement this function. Later, under MainForm.Designer.cs you’ll find the source code for the GUI of this program. The code will help you to develop a user interface that will make it easy to use the program.
Good luck with implementing the code!
What will you need for this function?
• A Visual C# WPF Application created in Visual Studio
• The VoIPSDK.dll added to the references. (It can be found on the website where I found the code: www.camera-sdk.com/)
The first part of the code under MainForm.cs is the code for the frame capturing program itself. It contains all the details you need to implement this function. Later, under MainForm.Designer.cs you’ll find the source code for the GUI of this program. The code will help you to develop a user interface that will make it easy to use the program.
Good luck with implementing the code!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// MainForm.cs using System; using System.Windows.Forms; using Ozeki.Media.MediaHandlers; using Ozeki.Media.MediaHandlers.Video; namespace FrameCaptureFromUSBCamera { public partial class MainForm : Form { private FrameCapture _capture; private WebCamera _webCamera; private MediaConnector _connector; private DrawingImageProvider _liveProvider; private DrawingImageProvider _frameCaptureProvider; private int _index = 0; public MainForm() { InitializeComponent(); } private void connectBt_Click(object sender, EventArgs e) { try { disconnectBt.Enabled = true; startBt.Enabled = true; _webCamera = WebCamera.GetDefaultDevice(); _connector.Connect(_webCamera, _liveProvider); _connector.Connect(_webCamera, _capture); _connector.Connect(_capture, _frameCaptureProvider); liveViewer.SetImageProvider(_liveProvider); liveViewer.Start(); captureViewer.SetImageProvider(_frameCaptureProvider); captureViewer.Start(); _webCamera.Start(); connectBt.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void disconnectBt_Click(object sender, EventArgs e) { try { _capture.Stop(); _webCamera.Stop(); _connector.Disconnect(_webCamera, _liveProvider); _connector.Disconnect(_webCamera, _capture); _connector.Disconnect(_capture, _frameCaptureProvider); liveViewer.Stop(); captureViewer.Stop(); _capture.Dispose(); connectBt.Enabled = true; disconnectBt.Enabled = false; startBt.Enabled = false; stopBt.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void startBt_Click(object sender, EventArgs e) { try { var sec = int.Parse(secondText.Text); _capture.Start(); _capture.OnFrameCaptured += _capture_OnFrameCaptured; startBt.Enabled = false; stopBt.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } void _capture_OnFrameCaptured(object sender, Ozeki.Media.Video.Snapshot e) { var image = e.ToImage(); image.Save("test"+_index+".jpg"); } private void stopBt_Click(object sender, EventArgs e) { _capture.Stop(); _capture.OnFrameCaptured -= _capture_OnFrameCaptured; startBt.Enabled = true; stopBt.Enabled = false; } } } // MainForm.Designer.cs namespace FrameCaptureFromUSBCamera { partial class MainForm { private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code private void InitializeComponent() { this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // connectBt // this.connectBt.Name = "connectBt"; this.connectBt.TabIndex = 0; this.connectBt.Text = "Connect to web camera"; this.connectBt.UseVisualStyleBackColor = true; // // disconnectBt // this.disconnectBt.Enabled = false; this.disconnectBt.Name = "disconnectBt"; this.disconnectBt.TabIndex = 2; this.disconnectBt.Text = "Disconnect from web camera"; this.disconnectBt.UseVisualStyleBackColor = true; // // secondText // this.secondText.Name = "secondText"; this.secondText.TabIndex = 4; // // label1 // this.label1.AutoSize = true; this.label1.Name = "label1"; this.label1.TabIndex = 5; this.label1.Text = "Seconds between frames"; // // groupBox1 // this.groupBox1.Controls.Add(this.liveViewer); this.groupBox1.Name = "groupBox1"; this.groupBox1.TabIndex = 6; this.groupBox1.TabStop = false; this.groupBox1.Text = "Live"; // // liveViewer // this.liveViewer.FlipMode = Ozeki.Media.Video.FlipMode.None; this.liveViewer.Name = "liveViewer"; this.liveViewer.RotateAngle = 0; this.liveViewer.TabIndex = 0; this.liveViewer.Text = "liveViewer"; // // groupBox2 // this.groupBox2.Controls.Add(this.captureViewer); this.groupBox2.Name = "groupBox2"; this.groupBox2.TabIndex = 7; this.groupBox2.TabStop = false; this.groupBox2.Text = "Frame capture"; // // captureViewer // this.captureViewer.FlipMode = Ozeki.Media.Video.FlipMode.None; this.captureViewer.Name = "captureViewer"; this.captureViewer.RotateAngle = 0; this.captureViewer.TabIndex = 0; this.captureViewer.Text = "captureViewer"; // // startBt // this.startBt.Enabled = false; this.startBt.Name = "startBt"; this.startBt.TabIndex = 8; this.startBt.Text = "Start"; this.startBt.UseVisualStyleBackColor = true; // // stopBt // this.stopBt.Enabled = false; this.stopBt.Name = "stopBt"; this.stopBt.TabIndex = 9; this.stopBt.Text = "Stop"; this.stopBt.UseVisualStyleBackColor = true; // // MainForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoSize = true; this.Controls.Add(this.stopBt); this.Controls.Add(this.startBt); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Controls.Add(this.label1); this.Controls.Add(this.secondText); this.Controls.Add(this.disconnectBt); this.Controls.Add(this.connectBt); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.Name = "FrameCapture"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Frame capture"; this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button connectBt; private System.Windows.Forms.Button disconnectBt; private System.Windows.Forms.TextBox secondText; private System.Windows.Forms.Label label1; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private Ozeki.Media.Video.Controls.VideoViewerWF liveViewer; private Ozeki.Media.Video.Controls.VideoViewerWF captureViewer; private System.Windows.Forms.Button startBt; private System.Windows.Forms.Button stopBt; } }
URL: http://www.camera-sdk.com/