June 24th, 2012, 07:06 AM
Using GetDC and GetPixel in a specific full screen game?
Hi there. I'm relatively new to C# and I'm also relatively new to forums so bear with me if I do anything wrong .
Anyhow, I have an issue with a game. I'm trying to get a specific pixel from a full screen game using GetDC and then I use GetPixel on the returned IntPtr to get a pixel at a specific point. My code works on literally every windowed and fullscreen game I've tried it on (chronicles of riddick, diablo 2, nolf 1, nolf 2, rumble fighter, battlefield 2, fable) just to name a few. I made it so that the pixel would be gotten from the cursor position, and it worked on all these games exactly right, even with the different resolutions. There is one game I had trouble with though. The game is called Gunz the duel. No matter how much I tried (random x and y screen values, using different methods, etc) I kept getting RGB value: A = 255, R = 0, G = 0, B = 0. This is the method that I use to get the pixel and then proceed to extract the RGB value from it:
The game's video settings:
public static Color GetPixelColor(int x, int y)
IntPtr hdc = GetDC(IntPtr.Zero);
int pixel = (int) GetPixel(hdc, x, y);
Color color = Color.FromArgb((int)(pixel & 0x000000FF),
(int)(pixel & 0x0000FF00) >> 8,
(int)(pixel & 0x00FF0000) >> 16);
Resolution: 1280x720 16bpp
Brighness: (there's a slider) almost half way
Reflection effect: ON
Light map: ON
Dynamic light: OFF
Character image quality: HIGH
Background image quality: HIGH
Effect quality: high
Texture quality: 32 bit
I also tried using a function to make a snapshot out of the game screen, saving it in a Bitmap and then using GetPixel to get the wanted pixel out of it, and that worked perfectly. However, I'm doing this for a game, and my program is running a while loop with a mere delay of 30ms so it made the game somewhat laggy because of the constant snapshot taking. How do I fix the above code to work with the game?
PS: If I'm doing anything wrong, or I need to post more information, please inform me.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!