MainForm.vb
上传用户:chengzheng
上传日期:2013-08-05
资源大小:38k
文件大小:4k
- Imports Cowburn.Imaging
- Imports OpenNETCF.Win32
- Public Class MainForm
- Inherits System.Windows.Forms.Form
- Friend WithEvents hr As System.Windows.Forms.Panel
- Friend WithEvents camImage As System.Windows.Forms.PictureBox
- Friend WithEvents GetImageBtn As System.Windows.Forms.Button
- Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
- Friend WithEvents camera As Cowburn.Imaging.HtcCamera
- #Region " Windows Form Designer generated code "
- Public Sub New()
- MyBase.New()
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
- '
- ' Create an new instance of the HtcCamera class
- ' and hook up the CaptureCompleted event hander;
- '
- camera = New HtcCamera
- camera.Orientation = Orientation.Portrait
- End Sub
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- MyBase.Dispose(disposing)
- End Sub
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- Private Sub InitializeComponent()
- Me.MainMenu1 = New System.Windows.Forms.MainMenu
- Me.hr = New System.Windows.Forms.Panel
- Me.camImage = New System.Windows.Forms.PictureBox
- Me.GetImageBtn = New System.Windows.Forms.Button
- '
- 'hr
- '
- Me.hr.BackColor = System.Drawing.Color.RoyalBlue
- Me.hr.Location = New System.Drawing.Point(0, 189)
- Me.hr.Size = New System.Drawing.Size(240, 2)
- '
- 'camImage
- '
- Me.camImage.Location = New System.Drawing.Point(53, 5)
- Me.camImage.Size = New System.Drawing.Size(135, 180)
- '
- 'GetImageBtn
- '
- Me.GetImageBtn.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular)
- Me.GetImageBtn.Location = New System.Drawing.Point(4, 197)
- Me.GetImageBtn.Size = New System.Drawing.Size(232, 68)
- Me.GetImageBtn.Text = "Get New Image"
- '
- 'MainForm
- '
- Me.BackColor = System.Drawing.Color.Silver
- Me.Controls.Add(Me.hr)
- Me.Controls.Add(Me.camImage)
- Me.Controls.Add(Me.GetImageBtn)
- Me.Menu = Me.MainMenu1
- Me.MinimizeBox = False
- Me.Text = "Camera Capture"
- End Sub
- #End Region
- Private Sub GetImageBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetImageBtn.Click
- ' Instruct the camera to make a capture to file
- If Not (camera Is Nothing) Then
- camera.Capture("My Photos", CaptureType.File)
- End If
- End Sub
- Private Sub camera_CaptureCompleted(ByVal sender As Object, ByVal e As CameraEventArgs) Handles camera.CaptureCompleted
- If Not (e.Path = String.Empty) Then
- Dim image As Bitmap = New Bitmap(e.Path)
- ' Create a white canvas to paint the image onto
- Dim tmp As Bitmap = New Bitmap(camImage.Width, camImage.Height)
- Dim g As Graphics = 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
- End If
- Win32Window.SetForegroundWindow(Win32Window.FindWindow(Nothing, Me.Text))
- End Sub
- End Class