Screen in VB.NET

xiaoxiao2021-03-05  24

'********************************* AUTHOR: WGSCD' function: Screening 'QQ153964481'Date: 2005 -4-12 '******************************************

Public class form1 inherits system.windows.Forms.form

#Region "Windows Form Designer Generated Code"

Public Sub new () mybase.new ()

'This call is required for the Windows Form Designer. InitializeComponent ()

'Add any initialization after INITIALIZECOMPONENT ()

End Sub

'Form rewriting disposal to clean the component list. Protected overloads overrides sub dispose (byval disposing as boolean) ing disponation kiln (Components Is Nothing) Then components.dispose () end if endiffs) End sub

'Windows Form Designer Supply Private Components as System.comPonentModel.icontainer

'Note: The following procedure is necessary to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.

Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Timer1 As System.Windows.Forms.Timer Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox Friend WithEvents Button2 As System.Windows.Forms.Button Private Sub InitializeComponent () Me.components = New System.ComponentModel.Container Me.Button1 = New System.Windows.Forms.Button Me.Timer1 = New System.Windows.Forms.Timer (Me.components) Me.PictureBox1 = New System.Windows.Forms.PictureBox Me.Button2 = New System.Windows.Forms.Button Me.SuspendLayout () '' Button1 'Me.Button1.ForeColor = System.Drawing.Color.Black Me.Button1.Location = New System.drawing.point (8, 312) me.button1.name = "Button1" me.button1.size = new system.drawing.size (112, 32) me.button1.tabindex = 0 me.button1.text = " Screen "'PictureBox1' Me.Pictureb Ox1.location = new system.drawing.point (8, 8) me.picturebox1.name = "PictureBox1" me.picturebox1.size = new system.drawing.size (392, 288) me.picturebox1.tabindex = 4 me. PictureBox1.TabStop = False '' Button2 'Me.Button2.ForeColor = System.Drawing.Color.Black Me.Button2.Location = New System.Drawing.Point (264, 312) Me.Button2.Name = "Button2" Me. Button2.size = new system.drawing.size (112, 32) me.button2.tabindex = 5 me.button2.text = "Save" '' Form1 '

Me.autoscalebasesize = new system.drawing.size (6, 14) me.backcolor = system.drawing.color.fromargb (ctype (192, byte), ctype (192, byte), ctype (255, byte)) ME. Clientsize = new system.drawing.size (408, 358) me.controls.add (me.button2) me.controls.add (me.picturebox1) Me.Controls.add (me.button1) me.forecolor = system.drawing .Color.fromargb (ctype (192, byte), ctype (255, byte), ctype (255, byte) me.name = "form1" me.text = "wgscd" me.ResumeLayout (false) end sub

#End region

Image capture in VB.NET, you need to reference some APIs first, the following is a declaration:

Private Declare Function CreateCompatibleDC LIB "GDI32" (Byval HDC AS Integer) AS INTEGER

Private Declare Function CreateCompatibleBitmap LIB "GDI32" (Byval NWIDTH AS INTEGER, BYVAL NHEIGHT AS INTEGER) AS INTEGER

Private Declare Function SelectObject LIB "GDI32" (Byval Hobject As Integer) AS Integer

Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal OP as integer) AS Integer

Private Declare Function Deletedc LIB "GDI32" (Byval HDC AS Integer) AS Integer

Private Declare Function DeleteObject LIB "GDI32" (Byval Hobj AS Integer) AS Integer Declare Function Getdc LIB "User32" Alias ​​"getdc" (Byval HWnd As Integer) AS Integer

Const srcopy as integer = & hcc0020

'Add the following code to the Button1_Click event:

Private sub button1_click (Byval e as system.EventArgs) Handles Button1.Clickdim HDC, HMDC AS Integer

DIM HBMP, HBMPOLD AS INTEGER

DIM SW, SH AS INTEGER

HDC = getdc (0)

HMDC = CREATECOMPALEDC (HDC)

SW = Screen.primaryScreen.bounds.width

sh = screen.primaryScreen.Bounds.height

HBMP = CREATECOMPATIBLEBITMAP (HDC, SW, SH)

HBMPOLD = SELECTOBJECT (HMDC, HBMP)

Bitblt (HMDC, 0, 0, SW, SH, HDC, 0, 0, SRCCOPY)

HBMP = SELECTOBJECT (HMDC, HBMPOLD)

Picturebox1.image = image.fromhbitmap (new intptr (HBMP))

DeleteDC (HDC)

Deletedc (HMDC)

DeleteObject (HBMP)

Me.Button2.enabled = true

End Sub

Private Sub Form1_Load (Byval E AS System.Object, Byval E AS System.Eventargs) Handles MyBase.Load

Me.Button2.enabled = false

End Sub Dim Off AS New SavefileDialog Private Sub Button2_Click (Byval E AS System.EventArgs) Handles Button2.click

OFD.FILTER = "jpg file | * .jpg | bmp file | * .bmp"

Dim bmp as bitmap = me.picturebox1.image

IF OFD.SHOWDIALOG = DialogResult.ok the bmp.save (OFD.FileName)

End if End Subend Class

转载请注明原文地址:https://www.9cbs.com/read-37044.html

New Post(0)