BitBlt Not returning image
I am using the Windows API to call bitblt from gdi32.dll and when I call it it doesn't return an image just an empty bit map
public Bitmap GetScreenShot()
{
try
{
Screen.BitBlt(_hdcDest, 0, 0, CaptureWidth, CaptureWidth, _hdcSrc, _zones[0], _zones[1], 0x00CC0020);
return (Bitmap)_bitmap.Clone(); // Return a copy to avoid threading issues
}
catch (Exception ex)
{
Debug.WriteLine($"Capture Error: {ex.Message}");
return null;
}
}
public Bitmap GetScreenShot()
{
try
{
Screen.BitBlt(_hdcDest, 0, 0, CaptureWidth, CaptureWidth, _hdcSrc, _zones[0], _zones[1], 0x00CC0020);
return (Bitmap)_bitmap.Clone(); // Return a copy to avoid threading issues
}
catch (Exception ex)
{
Debug.WriteLine($"Capture Error: {ex.Message}");
return null;
}
}
public Grabber() {
// Takes half of the screen width and height and makes box in the middle
_zones = CalculateGrabZone(HalfScreenX, HalfScreenY, GrabZone);
CaptureHeight = _zones[3] - _zones[1];
CaptureWidth = _zones[2] - _zones[0];
_Enabled = true;
_bitmap = new Bitmap(CaptureWidth, CaptureHeight);
_gDest = Graphics.FromImage(_bitmap);
_hdcDest = _gDest.GetHdc();
_hdcSrc = Screen.GetDC(IntPtr.Zero);
}
public Grabber() {
// Takes half of the screen width and height and makes box in the middle
_zones = CalculateGrabZone(HalfScreenX, HalfScreenY, GrabZone);
CaptureHeight = _zones[3] - _zones[1];
CaptureWidth = _zones[2] - _zones[0];
_Enabled = true;
_bitmap = new Bitmap(CaptureWidth, CaptureHeight);
_gDest = Graphics.FromImage(_bitmap);
_hdcDest = _gDest.GetHdc();
_hdcSrc = Screen.GetDC(IntPtr.Zero);
}
0 Replies