Originariamente inviato da gprox
Come da titolo uso una picturebox per vedere un film, ora ho la necessita di salvare l'immagine(frame attuale) che c'è nella picturebox, usando il classico savepicture la cosa non funziona, cioè salva l'immagine ma non vi è alcun screen reale del video ma solo il backcolor della picture
Devi catturare l'immagine del sorgente 'reale' che non è il PictureBox.
Ecco le indicazioni in generale estratte da un mio progetto e 'arrangiate' per l'esempio:
- in un modulo BAS aggiungi:
codice:
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function WindowFromPointXY Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Const SRCCOPY = &HCC0020
- Nel form principale della tua applicazione
1. imposta KeyPreview a True
2. aggiungi un PictureBox picTemp, imposti AutoRedraw=True
- dichiara a livello di form:
codice:
Dim pt As POINTAPI , rc As RECT
Dim hWndSrc As Long
Dim hDCSrc As Long
- nell'evento Form_KeyDown() inserisci questo codice
codice:
If KeyCode = vbKeyF12 Then
GetCursorPos pt
hWndSrc = WindowFromPointXY(pt.X, pt.Y)
hDCSrc = GetDC(hWndSrc)
GetWindowRect hWndSrc, rc
With picTemp
' imposto dimensione del picturebox temporaneo
.Width = (rc.Right - rc.Left) * Screen.TwipsPerPixelX
.Height = (rc.Bottom - rc.Top) * Screen.TwipsPerPixelY
BitBlt .hdc, 0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top, hDCSrc, 0, 0, SRCCOPY
.Picture = .Image
sFile = App.path & "\ScreenShot.bmp"
SavePicture .Picture, sFile
End With
ReleaseDC hDCSrc
End Sub
Ora, posizionando il mouse sulla finestra del video, premi F12
Spero di non aver dimenticato niente