Thread: Read Pixel

  1. #1
    Registered User
    Join Date
    Sep 2008
    Location
    New York, USA
    Posts
    4

    Read Pixel

    I'm an admittedly green programmer - but I am just playing with a program and I want to add the capability for the program to be able to read the RGB color value of a pixel at a certain location of the screen, and put it in a variable I can work with.

    I know that will require some work with a Windows API/SDK - but any help or ideas you can provide would be great. I really have no idea how to go about this.

    Oh, and I only have experience in C, and minimal experience at that.

    Thanks.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    not sure, but something like this should work:

    Code:
    COLORREF color = GetPixel( GetDC( HWND_DESKTOP ), x, y );
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    New York, USA
    Posts
    4

    Thanks - Another Error

    I tried that - and got this error:
    "undefinted reference to '_GetPixel@12'
    collect2: ld returned 1 exit status"

    Any thoughts? Thanks.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    And did you link with gdi32.lib?

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    New York, USA
    Posts
    4

    gdi32

    I thought I did, but then again I'm not really sure I did it right. Like I said I have very minimal experience, and to be honest this is well over my head - but I know that if I can just get this to work I can handle the rest of the program.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    On the basis that "ld" makes me think of gcc, I'm guessing you're either using Code::Blocks or Dev-C++. Depending which you have determines how you add the flag, but you'll need to go somewhere in options and add it in.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    New York, USA
    Posts
    4
    Yup - Dev-C++

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Then under the assumption you're using a project, you should do Alt-P for project options, and then go to parameters, and where it says linker add "-lgdi32".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  2. "sorting news" assignment
    By prljavibluzer in forum C Programming
    Replies: 7
    Last Post: 02-06-2008, 06:45 AM
  3. How to read a file stream entirely into a vector?
    By jiapei100 in forum C++ Programming
    Replies: 4
    Last Post: 01-06-2008, 03:22 PM
  4. read only folder on Windows
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 11-05-2007, 09:18 AM
  5. read in csv file
    By gums in forum C Programming
    Replies: 5
    Last Post: 05-10-2007, 07:38 AM