CAPTURAR A FOTO DA TELA?
Gostaria de saber como faço para capturar a foto, igual o botão print Screen?
Se algum souber como capturar de area determinada tambem vai me ajudar.
Obrigado.
Se algum souber como capturar de area determinada tambem vai me ajudar.
Obrigado.
Segue o código. (Autoria Macorrati).
Crie um formulário form1.vb
No formulário form1.vb inclua um controle Button chamado btnCaptura e um controle CheckBox chamado chkIncluiForm e defina sua propriedade checked como igual a True. Para terminar inclua um controle PictureBox chamado copiaTela e defina sua propriedade SizeMode como igual a StretchImage .
Module captura
Private Declare Function CreateDC Lib "GDI32" Alias "CreateDCA" ( ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As String) As IntPtr
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As IntPtr) As IntPtr
'cria um bitmap compatÃÂÂvel com o dispostivo associato ao contexto usado.
Private Declare Function CreateCompatibleBitmap Lib "GDI32" ( ByVal hDC As IntPtr, ByVal nWidth As Integer, ByVal nHeight As Integer ) As IntPtr
Private Declare Function SelectObject Lib "GDI32" ( ByVal hDC As IntPtr, ByVal hObject As IntPtr ) As IntPtr
Private Declare Function BitBlt Lib "GDI32" ( ByVal srchDC As IntPtr, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As IntPtr, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer ) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As IntPtr) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As IntPtr) As Integer
Const SRCCOPY As Integer = &HCC0020
End Module
Crie um formulário form1.vb
No formulário form1.vb inclua um controle Button chamado btnCaptura e um controle CheckBox chamado chkIncluiForm e defina sua propriedade checked como igual a True. Para terminar inclua um controle PictureBox chamado copiaTela e defina sua propriedade SizeMode como igual a StretchImage .
Module captura
Private Declare Function CreateDC Lib "GDI32" Alias "CreateDCA" ( ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As String) As IntPtr
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As IntPtr) As IntPtr
'cria um bitmap compatÃÂÂvel com o dispostivo associato ao contexto usado.
Private Declare Function CreateCompatibleBitmap Lib "GDI32" ( ByVal hDC As IntPtr, ByVal nWidth As Integer, ByVal nHeight As Integer ) As IntPtr
Private Declare Function SelectObject Lib "GDI32" ( ByVal hDC As IntPtr, ByVal hObject As IntPtr ) As IntPtr
Private Declare Function BitBlt Lib "GDI32" ( ByVal srchDC As IntPtr, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As IntPtr, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer ) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As IntPtr) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As IntPtr) As Integer
Const SRCCOPY As Integer = &HCC0020
Public Function capturaTela() As Bitmap
' ----- pega uma imagem da tela
Dim screenHandle As IntPtr
Dim canvasHandle As IntPtr
Dim screenBitmap As IntPtr
Dim previousObject As IntPtr
Dim resultCode As Integer
Dim screenShot As Bitmap
' ----- Obtém uma referencia para o display.
screenHandle = CreateDC("DISPLAY", "", "", "")
' ----- Crie um canvas que vai servir como uma exibição
canvasHandle = CreateCompatibleDC(screenHandle)
' ----- Crie um bitmap que será tratado como a imagem da tela
screenBitmap = CreateCompatibleBitmap(screenHandle,Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
' ----- Copie a imagem da tela para Canvas
previousObject = SelectObject(canvasHandle, screenBitmap)
resultCode = BitBlt(canvasHandle, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, screenHandle, 0, 0, SRCCOPY)
screenBitmap = SelectObject(canvasHandle, previousObject)
' ----- encerra
resultCode = DeleteDC(screenHandle)
resultCode = DeleteDC(canvasHandle)
' ----- Copia a imagem para um bitmap .NET.
screenShot = Image.FromHbitmap(screenBitmap)
DeleteObject(screenBitmap)
' ----- encerra
Return screenShot
End Function
End Module
Tópico encerrado , respostas não são mais permitidas