Hallo
Ich habe Eine Function um eine Image vom Hwnd zu Capturen.
Diese Functioniert soweit super. Jedoch Geht der speicher innerhalb 30sec.. Auf 2Gb und dann ist klar Error.
Nun habe ich versucht BmpRect.Dispose() Aber klappt nicht auch nicht wen ich etwas warte bevor die Bitmap Löschen will.
Vielleicht Gibt es jemand der Den Code auch etwas Optimieren kann oder dabei helfen kann.
Api:
Function:
Lg
Ich habe Eine Function um eine Image vom Hwnd zu Capturen.
Diese Functioniert soweit super. Jedoch Geht der speicher innerhalb 30sec.. Auf 2Gb und dann ist klar Error.
Nun habe ich versucht BmpRect.Dispose() Aber klappt nicht auch nicht wen ich etwas warte bevor die Bitmap Löschen will.
Vielleicht Gibt es jemand der Den Code auch etwas Optimieren kann oder dabei helfen kann.
Api:
VB.NET-Quellcode
-
- Friend Const SRCCOPY As Integer = 13369376
- Friend Structure RECT
- Friend left As Int32
- Friend top As Int32
- Friend right As Int32
- Friend bottom As Int32
- End Structure
- Friend Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef lpRect As RECT) As Int32
- Friend Declare Function GetDC Lib "user32.dll" (ByVal hWnd As IntPtr) As IntPtr
- Friend Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As IntPtr) As IntPtr
- Friend Declare Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As IntPtr, ByVal nWidth As Integer, ByVal nHeight As Integer) As IntPtr
- Friend Declare Function DeleteDC Lib "gdi32.dll" (ByVal hDc As IntPtr) As IntPtr
- Friend Declare Function ReleaseDC Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hDc As IntPtr) As IntPtr
- Friend Declare Function BitBlt Lib "gdi32.dll" (ByVal hdcDest As IntPtr, ByVal xDest As Integer, ByVal yDest As Integer, ByVal wDest As Integer, ByVal hDest As Integer, ByVal hdcSource As IntPtr, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal RasterOp As Integer) As Boolean
- Friend Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As IntPtr, ByVal bmp As IntPtr) As IntPtr
- Friend Declare Function DeleteObject Lib "gdi32.dll" (ByVal hDc As IntPtr) As IntPtr
Function:
VB.NET-Quellcode
- Public Function createBitmap(ByVal hWnd As IntPtr) As Bitmap
- Dim WinRect As RECT
- GetWindowRect(hWnd, WinRect)
- Dim BmpRect As Bitmap = New Bitmap(WinRect.right - WinRect.left, WinRect.bottom - WinRect.top)
- Dim hdcFrom As IntPtr = GetDC(hWnd)
- Dim hdcTo As IntPtr = CreateCompatibleDC(hdcFrom)
- Dim hBitmap As IntPtr = CreateCompatibleBitmap(hdcFrom, BmpRect.Width, BmpRect.Height)
- If hBitmap <> IntPtr.Zero Then
- Dim hLocalBitmap As IntPtr = SelectObject(hdcTo, hBitmap)
- BitBlt(hdcTo, 0, 0, BmpRect.Width, BmpRect.Height, hdcFrom, 0, 0, SRCCOPY)
- SelectObject(hdcTo, hLocalBitmap)
- DeleteDC(hdcTo)
- ReleaseDC(hWnd, hdcFrom)
- BmpRect = Image.FromHbitmap(hBitmap)
- DeleteObject(hBitmap)
- 'BmpRect.Dispose()
- End If
- Return BmpRect
- End Function
-
Lg
