Capture screen image in monochrome using BitBlt

Posted on 2006-04-25
Last Modified: 2008-02-01

I am using BitBlt to capture parts of my screen but I then (thanks to AlexFM's help) have to convert to Monochrome (see

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.

Question by:JAMES
    LVL 48

    Expert Comment

    Please show your capture code.

    Author Comment

    This is the code :-

                public Bitmap GetWindowCaptureAsBitmap(IntPtr handle, int x, int y, int width, int height)
                      Win32.Rect rc = new Win32.Rect();
                      if (!Win32.GetWindowRect(handle, 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.TernaryRasterOperations.SRCCOPY);
                      // release the bitmap's device context
                      Win32.ReleaseDC(handle, hdcWindow);

                      // dispose of the bitmap's graphics object

                      // return the bitmap of the window
                      return bitmap;                  


    LVL 48

    Accepted Solution

    No, I don't see a way to capture directly to monochrome bitmap. The line:
    Bitmap bitmap = new Bitmap(width, height);
    creates color bitmap. If you change this to monochrome (providing PixelFormat parameter), Graphics.FromImage(bitmap) will not work.

    In your previous question I posted you link to article which decrribes how to access bitnap bits directly using unsafe pointers. You can use two unsafe pointers - one for reading RGB24 bitmap, another to write monochrome bitmap, and convert every RGB pixel to monochrome pixel. This can improve performance, because you save copying operation. Formula for transformation is in my previous post.

    Author Comment

    Again, Alex, many thanks for your help.

    I will capture in colour and use your previous routine to convert.



    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now