MainForm.cs
上传用户:chengzheng
上传日期:2013-08-05
资源大小:38k
文件大小:4k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.Windows.Forms;
- using System.Data;
- using Cowburn.Imaging;
- namespace CamCaptureSP
- {
- /// <summary>
- /// Summary description for MainForm.
- /// </summary>
- public class MainForm : System.Windows.Forms.Form
- {
- private System.Windows.Forms.MenuItem menuItem1;
- private System.Windows.Forms.MainMenu mainMenu1;
- private System.Windows.Forms.MenuItem menuItem3;
- private System.Windows.Forms.PictureBox camImage;
-
- // Create a field for the HtcCamera instance.
- private Cowburn.Imaging.HtcCamera camera;
-
- public MainForm()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- //
- // Create an new instance of the HtcCamera class
- // and hook up the CaptureCompleted event hander;
- //
- camera = new HtcCamera();
- camera.CaptureCompleted += new CameraEventHandler(Form1_CaptureCompleted);
- }
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- base.Dispose( disposing );
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.mainMenu1 = new System.Windows.Forms.MainMenu();
- this.menuItem1 = new System.Windows.Forms.MenuItem();
- this.menuItem3 = new System.Windows.Forms.MenuItem();
- this.camImage = new System.Windows.Forms.PictureBox();
- //
- // mainMenu1
- //
- this.mainMenu1.MenuItems.Add(this.menuItem1);
- this.mainMenu1.MenuItems.Add(this.menuItem3);
- //
- // menuItem1
- //
- this.menuItem1.Text = "Done";
- this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
- //
- // menuItem3
- //
- this.menuItem3.Text = "Get Image";
- this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
- //
- // camImage
- //
- this.camImage.Location = new System.Drawing.Point(8, 32);
- this.camImage.Size = new System.Drawing.Size(160, 120);
- //
- // MainForm
- //
- this.BackColor = System.Drawing.Color.Silver;
- this.Controls.Add(this.camImage);
- this.Menu = this.mainMenu1;
- this.Text = "Cam Capture";
- }
- #endregion
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- static void Main(string[] args)
- {
- Application.Run(new MainForm());
- }
- private void menuItem1_Click(object sender, System.EventArgs e)
- {
- Application.Exit();
- }
- private void menuItem3_Click(object sender, System.EventArgs e)
- {
- // Change the resolution from the default (VGA) to QVGA
- camera.Resolution = Resolution.VGA;
- // Make a call to the camera to go ahead with the capture
- camera.Capture(string.Empty, CaptureType.File);
- }
- private void Form1_CaptureCompleted(object sender, CameraEventArgs e)
- {
- if(e.Path != string.Empty)
- {
- Bitmap image = new Bitmap(e.Path);
-
- // Create a white canvas to paint the image onto
- Bitmap tmp = new Bitmap(camImage.Width,camImage.Height);
- Graphics g = Graphics.FromImage(tmp);
- g.FillRectangle(new SolidBrush(Color.White),new Rectangle(0,0,tmp.Width, tmp.Height));
- // Resize the captured image to fit the picturebox control
- g.DrawImage(image,new Rectangle(0,0,tmp.Width,tmp.Height),new Rectangle(0,0,image.Width,image.Height),GraphicsUnit.Pixel);
- camImage.Image = tmp;
- }
- }
- }
- }