Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Capture screen image in monochrome using BitBlt

Posted on 2006-04-25
4
Medium Priority
?
547 Views
Last Modified: 2008-02-01
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 http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21824554.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.
0
Comment
Question by:JAMES
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16532660
Please show your capture code.
0
 

Author Comment

by:JAMES
ID: 16532682
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
                  gfxBitmap.ReleaseHdc(hdcBitmap);                              
                  Win32.ReleaseDC(handle, hdcWindow);

                  // dispose of the bitmap's graphics object
                  gfxBitmap.Dispose();            

                  // return the bitmap of the window
                  return bitmap;                  
            }


Thanks.


0
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 16532784
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.
0
 

Author Comment

by:JAMES
ID: 16532796
Again, Alex, many thanks for your help.

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

Cheers.

James.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

578 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