Вы находитесь на странице: 1из 8

.

Net
Public Class Form1


Private Sub timerCapture_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles timerCapture.Tick
Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
bounds = Screen.PrimaryScreen.Bounds
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size,
CopyPixelOperation.SourceCopy)
PictureBox1.Image = screenshot
End Sub




Private Sub timerSave_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles timerSave.Tick
Me.PictureBox1.Image.Save("d:\\capture.bmp")

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

' Me.WindowState = FormWindowState.Minimized

'Me.ShowInTaskbar = False

End Sub

Private Sub timerClose_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles timerClose.Tick
Me.Close()

End Sub

Private Sub capture_btn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles capture_btn.Click
Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
bounds = Screen.PrimaryScreen.Bounds
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size,
CopyPixelOperation.SourceCopy)
PictureBox1.Image = screenshot
End Sub

Private Sub save_btn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles save_btn.Click
Me.PictureBox1.Image.Save("d:\\capture.bmp")
End Sub
End Class


1. Dim SIR As New SteffansImageRecognizion()
2. Dim SC As New ScreenShot.ScreenCapture
3.
4. Dim ColorBuffer As System.Drawing.Color
5. Dim BitmapBuffer As System.Drawing.Bitmap
6. Dim ImageBuffer As System.Drawing.Image
7.
8. While (True)
9. BitmapBuffer = SC.CaptureDeskTopRectangle(New
System.Drawing.Rectangle(0, 0, 0, 0), 1000, 700)
10.
11. ' Lots of code..
12.
13. End While










Visual
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.Ev
entArgs
Handles Button1.Click

Dim savefiledialog1 As New SaveFileDialog
Try
savefiledialog1.Title = "Save file"
savefiledialog1.FileName = "*.bmp"
savefiledialog1.Filter = "Bitmap |*.bmp"
If savefiledialog1.ShowDialog() = DialogResult.OK Then
PictureBox1.Image.Save(savefiledialog1.FileName,
System.Drawing.Imaging.ImageFormat.Bmp)
Me.Close()
End If
Catch ex As Exception
End Try
End Sub

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e AsSystem.
EventArgs) Handles Button2.Click
Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
Dim ww, hh As Integer
ww = CInt(TextBox1.Text)
hh = CInt(TextBox2.Text)
bounds = Screen.PrimaryScreen.Bounds
screenshot = New System.Drawing.Bitmap(ww, hh,
System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size,
CopyPixelOperation.SourceCopy)
PictureBox1.Image = screenshot
End Sub


End Class






Public Class Form1
Private screenshot As Bitmap
Private startpoint, endpoint As Point
Private Rect As Rectangle

Public Sub New()

InitializeComponent()
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.WindowState = FormWindowState.Maximized
Me.Opacity = 0.4
Me.ContextMenuStrip = ContextMenuStrip1

End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load

End Sub
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Try
e.Graphics.DrawRectangle(Pens.Red, Rect)
e.Graphics.DrawImage(screenshot, startpoint)
Catch ex As Exception

End Try

End Sub
Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

If e.Button = Windows.Forms.MouseButtons.Left Then

startpoint = Point.Empty
endpoint = Point.Empty
Rect = Rectangle.Empty
screenshot = New Bitmap(100, 100)
startpoint = Me.PointToClient(MousePosition)

End If

End Sub
Private Sub Form1_MouseMove(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
endpoint = Me.PointToClient(MousePosition)
Rect = New Rectangle(startpoint, New Size(endpoint - startpoint))
Invalidate()
End If

End Sub
Private Sub Form1_MouseUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
Try
screenshot = New Bitmap(Rect.Width, Rect.Height)
Dim graph As Graphics = Graphics.FromImage(screenshot)
graph.CopyFromScreen(Rect.X, Rect.Y, 1, 1, New Size(Rect.Width - 2, Rect.Height - 2),
CopyPixelOperation.SourceCopy)
Invalidate()
Catch ex As Exception

End Try

End Sub
Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ToolStripMenuItem1.Click

Dim savefiledialog1 As New SaveFileDialog

Try
savefiledialog1.Title = "Save file"

savefiledialog1.Filter = "Bitmap |*.bmp"

If savefiledialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
screenshot.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
End If

Catch ex As Exception

End Try
End Sub

Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ToolStripMenuItem2.Click
Me.Close()
End Sub
End Class
















Public Class Form1
Private screenshot As Bitmap
Private startpoint, endpoint As Point
Private Rect As Rectangle

Public Sub New()

InitializeComponent()
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.WindowState = FormWindowState.Maximized
Me.Opacity = 0.4
Me.ContextMenuStrip = ContextMenuStrip1

End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load

End Sub
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Try
e.Graphics.DrawRectangle(Pens.Red, Rect)
e.Graphics.DrawImage(screenshot, startpoint)
Catch ex As Exception

End Try

End Sub
Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

If e.Button = Windows.Forms.MouseButtons.Left Then

startpoint = Point.Empty
endpoint = Point.Empty
Rect = Rectangle.Empty
screenshot = New Bitmap(100, 100)
startpoint = Me.PointToClient(MousePosition)

End If

End Sub
Private Sub Form1_MouseMove(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
endpoint = Me.PointToClient(MousePosition)
Rect = New Rectangle(startpoint, New Size(endpoint - startpoint))
Invalidate()
End If

End Sub
Private Sub Form1_MouseUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
Try
screenshot = New Bitmap(Rect.Width, Rect.Height)
Dim graph As Graphics = Graphics.FromImage(screenshot)
graph.CopyFromScreen(Rect.X, Rect.Y, 1, 1, New Size(Rect.Width - 2, Rect.Height - 2),
CopyPixelOperation.SourceCopy)
Invalidate()
Catch ex As Exception

End Try

End Sub
Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ToolStripMenuItem1.Click

Dim savefiledialog1 As New SaveFileDialog

Try
savefiledialog1.Title = "Save file"

savefiledialog1.Filter = "Bitmap |*.bmp"

If savefiledialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
screenshot.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
End If

Catch ex As Exception

End Try
End Sub

Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ToolStripMenuItem2.Click
Me.Close()
End Sub
End Class

Вам также может понравиться