JAMES
asked on
Capture screen image in monochrome using BitBlt
Hi,
I am using BitBlt to capture parts of my screen but I then (thanks to AlexFM's help) have to convert to Monochrome (see https://www.experts-exchange.com/questions/21824554/Convert-bitmap-from-24-bit-to-monochrome.html#16524842)
I wondered if there was a way to directly copy an area of screen directly into a monochrome bitmap to save the conversion processing time and to simplify my process.
Many thanks.
James.
I am using BitBlt to capture parts of my screen but I then (thanks to AlexFM's help) have to convert to Monochrome (see https://www.experts-exchange.com/questions/21824554/Convert-bitmap-from-24-bit-to-monochrome.html#16524842)
I wondered if there was a way to directly copy an area of screen directly into a monochrome bitmap to save the conversion processing time and to simplify my process.
Many thanks.
James.
Please show your capture code.
ASKER
This is the code :-
public Bitmap GetWindowCaptureAsBitmap(I ntPtr handle, int x, int y, int width, int height)
{
Win32.Rect rc = new Win32.Rect();
if (!Win32.GetWindowRect(hand le, ref rc))
return null;
// create a bitmap from the visible clipping bounds of the graphics object from the window
// Bitmap bitmap = new Bitmap(rc.Width, rc.Height);
Bitmap bitmap = new Bitmap(width, height);
// create a graphics object from the bitmap
Graphics gfxBitmap = Graphics.FromImage(bitmap) ;
// get a device context for the bitmap
IntPtr hdcBitmap = gfxBitmap.GetHdc();
// get a device context for the window
IntPtr hdcWindow = Win32.GetWindowDC(handle);
// bitblt the window to the bitmap
Win32.BitBlt(hdcBitmap, 0, 0, width, height, hdcWindow, x, y, (int)Win32.TernaryRasterOp erations.S RCCOPY);
// release the bitmap's device context
gfxBitmap.ReleaseHdc(hdcBi tmap);
Win32.ReleaseDC(handle, hdcWindow);
// dispose of the bitmap's graphics object
gfxBitmap.Dispose();
// return the bitmap of the window
return bitmap;
}
Thanks.
public Bitmap GetWindowCaptureAsBitmap(I
{
Win32.Rect rc = new Win32.Rect();
if (!Win32.GetWindowRect(hand
return null;
// create a bitmap from the visible clipping bounds of the graphics object from the window
// Bitmap bitmap = new Bitmap(rc.Width, rc.Height);
Bitmap bitmap = new Bitmap(width, height);
// create a graphics object from the bitmap
Graphics gfxBitmap = Graphics.FromImage(bitmap)
// get a device context for the bitmap
IntPtr hdcBitmap = gfxBitmap.GetHdc();
// get a device context for the window
IntPtr hdcWindow = Win32.GetWindowDC(handle);
// bitblt the window to the bitmap
Win32.BitBlt(hdcBitmap, 0, 0, width, height, hdcWindow, x, y, (int)Win32.TernaryRasterOp
// release the bitmap's device context
gfxBitmap.ReleaseHdc(hdcBi
Win32.ReleaseDC(handle, hdcWindow);
// dispose of the bitmap's graphics object
gfxBitmap.Dispose();
// return the bitmap of the window
return bitmap;
}
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Again, Alex, many thanks for your help.
I will capture in colour and use your previous routine to convert.
Cheers.
James.
I will capture in colour and use your previous routine to convert.
Cheers.
James.