getting pixel information

This is a discussion on getting pixel information within the C++ Programming forums, part of the General Programming Boards category; Hi, Does anyone know how to retrieve the pixel color information for any particular pixel on the screen? I know ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    5

    getting pixel information

    Hi,

    Does anyone know how to retrieve the pixel color information for any particular pixel on the screen? I know it works with bitmaps using unsigned getpixel (int x, int y); but I need a function to retrieve any pixel. Is this even possible?

  2. #2
    Banned
    Join Date
    Dec 2003
    Posts
    367
    Details, details, give us some details!

    What graphics API are you using?

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    5
    Graphics API? Uh. . .win32, I guess. I'm not vying for the Turing Award, I just want to know if there's a function for getting pixel info.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Posting this question on the windows board might have been a better idea but, given the current hideous state of the boards, posting just about anywhere is going to be horrible. (<-- at least this guy still looks 'normal' ... edit: well, he started off normal but has verily become possess-ed by demons.)

    You can use GetPixel provided you have a handle to the desktop device context which can be obtained by using CreateDC:
    Code:
     
    /*eg. get colour at current pixel coordinates*/
    COLORREF clr;
    HDC      hdcScrn;
    POINT    pt;
    
    GetCursorPos(&pt);
    hdcScrn=CreateDC("DISPLAY",0,0,0);
    clr=GetPixel(hdcScrn,pt.x,pt.y); 
    DeleteDC(hdcScrn);
    At least that code block didn't get nasty scrollbars inserted...
    Last edited by Ken Fitlike; 03-28-2004 at 03:04 AM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    5

    Excellent

    Works great, Ken. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 08:54 PM
  2. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 09:55 AM
  3. Assignment Help !! (Student information system)
    By ashb in forum C++ Programming
    Replies: 6
    Last Post: 03-12-2005, 05:32 AM
  4. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 07:27 PM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-21-2002, 12:35 AM

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