Read Pixel

This is a discussion on Read Pixel within the C Programming forums, part of the General Programming Boards category; I'm an admittedly green programmer - but I am just playing with a program and I want to add the ...

  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
    Posts
    5,439
    not sure, but something like this should work:

    Code:
    COLORREF color = GetPixel( GetDC( HWND_DESKTOP ), x, y );
    Code:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 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
    13,007
    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
    13,007
    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
    13,007
    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, 05: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, 02:22 PM
  4. read only folder on Windows
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 11-05-2007, 08:18 AM
  5. read in csv file
    By gums in forum C Programming
    Replies: 5
    Last Post: 05-10-2007, 07:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21