Screen Capture Image bit depth question.. [modified]
-
Hey Guys, I have a c# application that uses win32 code to take a screencapture of a window running on the system. It then compares a portion of that screencapture with a bitmap that I have already pre-captured to see if that window is in a certain state. When I first wrote the code it compared no problem, but now when I use it the two images are not EXACTLY the same. My application captured the right part of the graphic, but when I compared both images (by zooming in in photoshop) they are not the same. Looks like the screencapture was worse quality. I saved the image I compare to as a Windows Bitmap 24 bit and the image I capture I am not sure what quality it is. Although my screen resolution is 32 bit. Is there someway that I can make sure that the image I capture and the image I compare to are the same bit depth and quality using c#? Here is some code I have
public static Bitmap GetWindowCaptureAsBitmap(int handle) { #region GetWindowCaptureAsBitmap IntPtr hWnd = new IntPtr(handle); Win32.Rect rc = new Win32.Rect(); if (!Win32.GetWindowRect(hWnd, 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); // 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(hWnd); // bitblt the **window** to the bitmap Win32.BitBlt(hdcBitmap, 0, 0, rc.Width, rc.Height, hdcWindow, 0, 0, (int)Win32.TernaryRasterOperations.SRCCOPY); // release the bitmap's device context gfxBitmap.ReleaseHdc(hdcBitmap); Win32.ReleaseDC(hWnd, hdcWindow); // dispose of the bitmap's graphics object gfxBitmap.Dispose(); // return the bitmap of the **window** return bitmap; #endregion }
private bool IsPlayersTurn(Image imgScreen) {