[VB.NET] Write code that takes a screenshot using bitblt and then a second method using getDibits
Budget: $30 – $250 USD
Refer to the URL here: https://guidedhacking.com/threads/bitblt-screenshot-logger-without-getdibits.15297/
It appears you can get a copy of the screen buffer only having to call bitblt the first time.
1: Convert the POC above to VB.NET
2: Create a function call that uses GetDiBits to return a byte() of the desktop image.
An example of a function returning a bitmap is below, the goal of number 2 is to return a byte() using GetDiBits for compression logic.
Public Shared Function GetDesktopImage() As BITMAP
Dim ScreenSize As SIZE
Dim bitScreenBMP As IntPtr
Dim iDC As IntPtr = GetDC(GetDesktopWindow())
Dim iMemDC As IntPtr = CreateCompatibleDC(iDC)
ScreenSize.x = GetSystemMetrics(SM_CXSCREEN)
ScreenSize.y = GetSystemMetrics(SM_CYSCREEN)
bitScreenBMP = CreateCompatibleBitmap(iDC, ScreenSize.x, ScreenSize.y)
If bitScreenBMP <> IntPtr.Zero Then
Dim hPrev As IntPtr = CType(SelectObject(iMemDC, bitScreenBMP), IntPtr)
BitBlt(iMemDC, 0, 0, ScreenSize.x, ScreenSize.y, iDC, 0, 0, SRCCOPY)
SelectObject(iMemDC, hPrev)
DeleteDC(iMemDC)
ReleaseDC(GetDesktopWindow(), iDC)
Dim bmpRes As BITMAP = Image.FromHbitmap(bitScreenBMP)
DeleteObject(bitScreenBMP)
GC.Collect()
Return bmpRes
End If
Return Nothing
End Function
It appears you can get a copy of the screen buffer only having to call bitblt the first time.
1: Convert the POC above to VB.NET
2: Create a function call that uses GetDiBits to return a byte() of the desktop image.
An example of a function returning a bitmap is below, the goal of number 2 is to return a byte() using GetDiBits for compression logic.
Public Shared Function GetDesktopImage() As BITMAP
Dim ScreenSize As SIZE
Dim bitScreenBMP As IntPtr
Dim iDC As IntPtr = GetDC(GetDesktopWindow())
Dim iMemDC As IntPtr = CreateCompatibleDC(iDC)
ScreenSize.x = GetSystemMetrics(SM_CXSCREEN)
ScreenSize.y = GetSystemMetrics(SM_CYSCREEN)
bitScreenBMP = CreateCompatibleBitmap(iDC, ScreenSize.x, ScreenSize.y)
If bitScreenBMP <> IntPtr.Zero Then
Dim hPrev As IntPtr = CType(SelectObject(iMemDC, bitScreenBMP), IntPtr)
BitBlt(iMemDC, 0, 0, ScreenSize.x, ScreenSize.y, iDC, 0, 0, SRCCOPY)
SelectObject(iMemDC, hPrev)
DeleteDC(iMemDC)
ReleaseDC(GetDesktopWindow(), iDC)
Dim bmpRes As BITMAP = Image.FromHbitmap(bitScreenBMP)
DeleteObject(bitScreenBMP)
GC.Collect()
Return bmpRes
End If
Return Nothing
End Function