MainForm.cs
上传用户:chengzheng
上传日期:2013-08-05
资源大小:38k
文件大小:4k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.Windows.Forms;
- using System.Data;
- using OpenNETCF;
- using OpenNETCF.Win32;
- using Cowburn.Imaging;
- namespace CamCapturePPC
- {
- /// <summary>
- /// Summary description for Form1.
- /// </summary>
- public class MainForm : System.Windows.Forms.Form
- {
- private System.Windows.Forms.MainMenu mainMenu1;
- private System.Windows.Forms.Button GetImageBtn;
- private System.Windows.Forms.PictureBox camImage;
- private System.Windows.Forms.Panel hr;
- // 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(camera_CaptureCompleted);
- camera.Orientation = Cowburn.Imaging.Orientation.Portrait;
- }
- /// <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.GetImageBtn = new System.Windows.Forms.Button();
- this.camImage = new System.Windows.Forms.PictureBox();
- this.hr = new System.Windows.Forms.Panel();
- //
- // GetImageBtn
- //
- this.GetImageBtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular);
- this.GetImageBtn.Location = new System.Drawing.Point(4, 196);
- this.GetImageBtn.Size = new System.Drawing.Size(232, 68);
- this.GetImageBtn.Text = "Get New Image";
- this.GetImageBtn.Click += new System.EventHandler(this.GetImageBtn_Click);
- //
- // camImage
- //
- this.camImage.Location = new System.Drawing.Point(53, 4);
- this.camImage.Size = new System.Drawing.Size(135, 180);
- //
- // hr
- //
- this.hr.BackColor = System.Drawing.Color.RoyalBlue;
- this.hr.Location = new System.Drawing.Point(0, 188);
- this.hr.Size = new System.Drawing.Size(240, 2);
- //
- // MainForm
- //
- this.BackColor = System.Drawing.Color.Silver;
- this.Controls.Add(this.hr);
- this.Controls.Add(this.camImage);
- this.Controls.Add(this.GetImageBtn);
- this.Menu = this.mainMenu1;
- this.MinimizeBox = false;
- this.Text = "Camera Capture";
- }
- #endregion
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- static void Main()
- {
- Application.Run(new MainForm());
- }
- private void GetImageBtn_Click(object sender, System.EventArgs e)
- {
- // Instruct the camera to make a capture to file
- if(camera != null)
- camera.Capture(@"My Photos",CaptureType.File);
- }
- private void camera_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;
- }
- // HACK:
- Win32Window.SetForegroundWindow(Win32Window.FindWindow(null,this.Text));
- }
- }
- }