Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Forma más rápida de Capturar Screen

Estas en el tema de Forma más rápida de Capturar Screen en el foro de Visual Basic clásico en Foros del Web. Estoy buscando una forma de capturar más rápidamente (no rápido precisamente pero sin consumir muchos recursos) pues he utilizado milenarmente este procedimiento: Código: Private Const ...
  #1 (permalink)  
Antiguo 30/09/2005, 14:13
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Exclamación Forma más rápida de Capturar Screen

Estoy buscando una forma de capturar más rápidamente (no rápido precisamente pero sin consumir muchos recursos) pues he utilizado milenarmente este procedimiento:
Código:
 
Private Const RASTERCAPS As Long = 38
Private Const RC_PALETTE As Long = &H100
Private Const SIZEPALETTE As Long = 104
Private Type PALETTEENTRY
	peRed As Byte
	peGreen As Byte
	peBlue As Byte
	peFlags As Byte
End Type
Private Type LOGPALETTE
	palVersion As Integer
	palNumEntries As Integer
	palPalEntry(255) As PALETTEENTRY
End Type
Private Type GUID
	Data1 As Long
	Data2 As Integer
	Data3 As Integer
	Data4(7) As Byte
End Type
Private Type PicBmp
	Size As Long
	Type As Long
	hBmp As Long
	hPal As Long
	Reserved As Long
End Type
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal iCapabilitiy As Long) As Long
Private Declare Function GetSystemPaletteEntries Lib "gdi32" (ByVal hDC As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long
Private Declare Function CreatePalette Lib "gdi32" (lpLogPalette As LOGPALETTE) As Long
Private Declare Function SelectPalette Lib "gdi32" (ByVal hDC As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long
Private Declare Function RealizePalette Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hDCSrc As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Public Function CaptureScreen() As Picture
Dim hWndScreen As Long
hWndScreen = GetDesktopWindow()
Set CaptureScreen = CaptureWindow(hWndScreen, False, 0, 0, Screen.Width \ Screen.TwipsPerPixelX, Screen.Height \ Screen.TwipsPerPixelY)
End Function
Public Function CaptureWindow(ByVal hWndSrc As Long, ByVal Client As Boolean, ByVal LeftSrc As Long, ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Picture
Dim hDCMemory As Long
Dim hBmp As Long
Dim hBmpPrev As Long
Dim r As Long
Dim hDCSrc As Long
Dim hPal As Long
Dim hPalPrev As Long
Dim RasterCapsScrn As Long
Dim HasPaletteScrn As Long
Dim PaletteSizeScrn As Long
Dim LogPal As LOGPALETTE
If Client Then
	hDCSrc = GetDC(hWndSrc)
Else
	hDCSrc = GetWindowDC(hWndSrc)
End If
hDCMemory = CreateCompatibleDC(hDCSrc)
hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
hBmpPrev = SelectObject(hDCMemory, hBmp)
RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS)
HasPaletteScrn = RasterCapsScrn And RC_PALETTE
PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE)
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
	LogPal.palVersion = &H300
	LogPal.palNumEntries = 256
	r = GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
	hPal = CreatePalette(LogPal)
	hPalPrev = SelectPalette(hDCMemory, hPal, 0)
	r = RealizePalette(hDCMemory)
End If
r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, vbSrcCopy)
hBmp = SelectObject(hDCMemory, hBmpPrev)
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
	hPal = SelectPalette(hDCMemory, hPalPrev, 0)
End If
r = DeleteDC(hDCMemory)
r = ReleaseDC(hWndSrc, hDCSrc)
Set CaptureWindow = CreateBitmapPicture(hBmp, hPal)
End Function
Public Function CreateBitmapPicture(ByVal hBmp As Long, ByVal hPal As Long) As Picture
Dim r As Long
Dim Pic As PicBmp
Dim IPic As IPicture
Dim IID_IDispatch As GUID
With IID_IDispatch
	.Data1 = &H20400
	.Data4(0) = &HC0
	.Data4(7) = &H46
End With
With Pic
	.Size = Len(Pic)
	.Type = vbPicTypeBitmap
	.hBmp = hBmp
	.hPal = hPal
End With
r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
Set CreateBitmapPicture = IPic
End Function
No sé si el vb es malo, el procedimiento es malo, o mi pc es mala... (224 RAM, 1.5 Procesador), pero se me hace lenta cuando por ejemplo, capturo cada 1 Seg. Si alguien tiene alguna forma de que capture más lentamente pero que me consuma pocos recursos del Sistema (70 % Unidad Central de Procesamiento )
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #2 (permalink)  
Antiguo 30/09/2005, 19:51
 
Fecha de Ingreso: abril-2005
Mensajes: 351
Antigüedad: 19 años
Puntos: 3
La funciòn Api se encarga de presionar las teclas PrintScreen y Alt

En este ejemplo tiene un timer pero ponlo en el evento que te plazca


Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const KEYEVENTF_KEYUP = 2

Dim cont As Integer

Private Sub Timer1_Timer()
Dim imagen As IPictureDisp
Static cont
keybd_event 18, 0, 0, 0
keybd_event 44, 0, 0, 0
keybd_event 44, 0, KEYEVENTF_KEYUP, 0
keybd_event 18, 0, KEYEVENTF_KEYUP, 0
Set imagen = Clipboard.GetData
Picture1 = imagen
End Sub
  #3 (permalink)  
Antiguo 01/10/2005, 06:38
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Exclamación

Cita:
Iniciado por LeandroA
La funciòn Api se encarga de presionar las teclas PrintScreen y Alt

En este ejemplo tiene un timer pero ponlo en el evento que te plazca


Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const KEYEVENTF_KEYUP = 2

Dim cont As Integer

Private Sub Timer1_Timer()
Dim imagen As IPictureDisp
Static cont
keybd_event 18, 0, 0, 0
keybd_event 44, 0, 0, 0
keybd_event 44, 0, KEYEVENTF_KEYUP, 0
keybd_event 18, 0, KEYEVENTF_KEYUP, 0
Set imagen = Clipboard.GetData
Picture1 = imagen
End Sub
Gracias, pero esa función ya lo conocía, el problema es que si captura cada 1 Seg. el usuario no podrá colocar ninguna imagen en el portapapeles, pues cada vez que coloca mi programa lo reeemplazará....
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:05.