Thread: Reading pixel color data from screen

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    102

    Reading pixel color data from screen

    Hey all, I'm trying to create a program that can read pixel color data from anywhere on the screen. I have found a way to successfully do it using the getPixel command and findWindow() functions, however it works most of the time. But It works by capturing the window pixel coordinates from the hdc. However, some things I've noticed don't post the pixel color to the hdc ( such as a java applet in internet explorer). So the only way I think I can get it to work totally is if I can find a way to extract the pixel data from the screen or something similiar to that. Has anyone ever done anything like this, or can anyone point me in the right direction? Thanks in advance.
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you use "PrintScrn", do you get a copy of the Java applet?

    If not, I expect that it's using a non-window drawing mode (such as overlay layers).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    102
    Quote Originally Posted by matsp View Post
    If you use "PrintScrn", do you get a copy of the Java applet?

    If not, I expect that it's using a non-window drawing mode (such as overlay layers).

    --
    Mats
    Interestingly enough the particular applet it didn't work on does fine with PrintScrn, however when I use the getPixel command on the actual applet, it always returns 255 255 255 :/.
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    A quick search for "Screen Capture" finds this:
    http://www.c-sharpcorner.com/UploadF...enCapture.aspx

    Yes, it's C#, so you may have to do some translating to make it C or C++, but I think how it works is clear enough.
    Alternatively, this is pure C: http://forums.msdn.microsoft.com/en-...-dd0af1d78cae/

    --
    Mats
    Last edited by matsp; 08-20-2008 at 03:41 PM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    102
    Quote Originally Posted by matsp View Post
    A quick search for "Screen Capture" finds this:
    http://www.c-sharpcorner.com/UploadF...enCapture.aspx

    Yes, it's C#, so you may have to do some translating to make it C or C++, but I think how it works is clear enough.
    Alternatively, this is pure C: http://forums.msdn.microsoft.com/en-...-dd0af1d78cae/

    --
    Mats
    Thanks for your info, I'll keep it in mind, however I'd like to find a more efficient solution. This way seems to probably take up a fair amount of time, I'm not sure how slow it is, but I'm guessing pretty slow if I called it hundreds of times a loop like I plan too. I'll be trying to check for a certain pixel color so this would have to be done hundreds of times fairly quickly :/. Thanks again though, I'll see how it goes.
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, just replace the big bitblt with a getpixel. I thought that you actually wanted to copy the entire screen.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Capture the screen, blit it to an offscreen DC, and then do your getpixel() on the DC you blitted to.

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    102
    Alright guys, thanks, I'll see how it goes
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

  9. #9
    Registered User
    Join Date
    Apr 2007
    Posts
    102
    Matt, Buba you guys are awesome, blitting it to an entire other dc worked like a charm! Thanks guys.
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-04-2007, 01:09 AM
  2. Reading from the screen
    By guiderone in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-24-2002, 12:19 PM
  3. Reading from the screen
    By guiderone in forum C++ Programming
    Replies: 1
    Last Post: 01-24-2002, 12:07 PM
  4. Green Pixel On My Screen???
    By (TNT) in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 01-21-2002, 08:09 AM
  5. need help in making graphics in C++
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-21-2001, 12:14 PM