📄 mainform.vb
字号:
Imports Cowburn.Imaging
Public Class MainForm
Inherits System.Windows.Forms.Form
Friend WithEvents camImage As System.Windows.Forms.PictureBox
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
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.camImage = New System.Windows.Forms.PictureBox
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
'
'camImage
'
Me.camImage.Location = New System.Drawing.Point(8, 32)
Me.camImage.Size = New System.Drawing.Size(160, 120)
'
'MainMenu1
'
Me.MainMenu1.MenuItems.Add(Me.MenuItem1)
Me.MainMenu1.MenuItems.Add(Me.MenuItem2)
'
'MenuItem1
'
Me.MenuItem1.Text = "Done"
'
'MenuItem2
'
Me.MenuItem2.Text = "Get Image"
'
'MainForm
'
Me.Controls.Add(Me.camImage)
Me.Menu = Me.MainMenu1
Me.Text = "Cam Capture"
End Sub
#End Region
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
Application.Exit()
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.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
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -