1 / 10

Create Program To Capture picture

Create Program To Capture picture. ຮູບແບບໂປຣແກມ. ສ້າງ form. ຂຽນ code.

zena
Download Presentation

Create Program To Capture picture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Create Program To Capture picture

  2. ຮູບແບບໂປຣແກມ

  3. ສ້າງ form

  4. ຂຽນcode Imports System.DrawingImports System.Drawing.ImagingPublic Class frmMain   Inherits System.Windows.Forms.Form    Dim cropBitmap As Bitmap    Dim cropX As Integer    Dim cropY As Integer    Dim cropWidth As Integer    Dim cropHeight As Integer    Public cropPen As Pen    Public cropPenSize As Integer = 2    Public cropDashStyle As Drawing2D.DashStyle = Drawing2D.DashStyle.Solid    Public cropPenColor As Color = Color.Aquamarine

  5.   Public c As CursorsPrivate Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click        TryDim openDLG As New OpenFileDialog                openDLG.Filter = "Image Files (*.bmp, *.gif, *.jpg)|*.bmp;*.gif;*.jpg"               If openDLG.ShowDialog = DialogResult.OK Then                  p.Image = Image.FromFile(openDLG.FileName, True)              End If        Catch exc As Exception            MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error)        End TryEnd Sub

  6. Private Sub btnCrop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCrop.Click        Try            If cropWidth < 1 Then MessageBox.Show("You need to first select what portion of the image to crop.", " No cropping Cordinates!", MessageBoxButtons.OK, MessageBoxIcon.Error)                Exit Sub            End If            Dim bit As Bitmap = New Bitmap(p.Image, p.Width, p.Height)             cropBitmap = New Bitmap(cropWidth, cropHeight)            Dim g As Graphics = Graphics.FromImage(cropBitmap)            g.DrawImage(bit, 0, 0, rect, GraphicsUnit.Pixel)            pbCrop.Image = cropBitmap        Catch exc As Exception            MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error)        End TryEnd Sub

  7. Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click        Try If pbCrop.Image Is Nothing Then                MessageBox.Show("You have not edited the original image. There is no new image to save.Error MessageBoxButtons.OK, MessageBoxIcon.Information)                Exit Sub            End If            Dim saveDLG As SaveFileDialog = New SaveFileDialog            saveDLG.Filter = "Image Files (*.bmp, *.gif, *.jpg)|*.bmp;*.gif;*.jpg"            If saveDLG.ShowDialog = DialogResult.OK Then                If saveDLG.FileName.EndsWith("bmp") Then                    pbCrop.Image.Save(saveDLG.FileName, ImageFormat.Bmp)                ElseIf saveDLG.FileName.EndsWith("gif") Then                    pbCrop.Image.Save(saveDLG.FileName, ImageFormat.Gif)                ElsepbCrop.Image.Save(saveDLG.FileName, ImageFormat.Jpeg)                End If                saveDLG.Dispose()            End If        Catch exc As Exception            MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error)        End Try    End Sub

  8. Private Sub p_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles p.MouseUp        TryCursor = c.Default        Catch exc As Exception            MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error)        End Try    End Sub

  9. Private Sub p_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles p.MouseMove        Try            If p.Image Is Nothing Then Exit Sub            If e.Button = MouseButtons.Left Then                p.Refresh()                cropWidth = e.X - cropX                cropHeight = e.Y - cropYp.CreateGraphics.DrawRectangle(cropPen, cropX, cropY, cropWidth, cropHeight)            End IfGC.Collect()        Catch exc As ExceptionIf Err.Number = 5 Then Exit Sub            MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End TryEnd Sub

  10. ການເຮັດວຽກຂອງໂປຣແກມ

More Related