Thread: reading color of pixel

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    10

    reading color of pixel

    Ok, Im looking to get the pixel color of a certain pixel, but i dont understand the first parameter or GetPixel();
    http://msdn.microsoft.com/en-us/library/ms532282.aspx

    I dont know what to do for the HDC(i dont even know what HDC is).

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    A HDC is a Handle for a Display Context. You can get one with a CreateDC() or GetDC() - depending on what you are actually trying to do.

    --
    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
    Jan 2009
    Posts
    10
    i just want to get the color of a pixel on screen. Ill Go check it out, thanks.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by wannabe723 View Post
    i just want to get the color of a pixel on screen. Ill Go check it out, thanks.
    Yes, I understand that's what you say you want to do. But there's a difference between reading a pixel belonging to a particular window or reading the entire screen, for example.

    --
    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.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    Well,i read a whole bunch on the msdn site, i cant find it out at all... im gonna try to find some other way i guess

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, if you explain what you want to do (with a bit more detail than "I want to read a pixel"). For example, would it be sufficient to read pixels from the entire screen (as in, do you know where on the screen your pixels are)?

    If so,
    Code:
    HDC hdc = GetDC(NULL); 
    GetPixel(hdc, ...);
    should do the trick.

    --
    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
    Join Date
    Jan 2009
    Posts
    10
    I tried using HDC, my compiler didnt recognize it, so there must be something wrong with the registers. I found out how to do it in pascal anyway,

    Code:
    program ColorFinder;
    
    var color,x,y: integer;
    
    procedure findcolor;
    begin
         GetMousePos(x,y);
         color:=GetColor(x,y);
         writeln('color='+ IntToStr(color));
    end;
    begin
         findcolor;
    end.
    For Some reason, CTRL+ALT+R isnt making the program run, so i can only get the color of the start icon on the compiler

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I have absolutely no idea what CTRL-ALT-R is supposed to do here. Perhaps you can post your C++ attempt?

    --
    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.

  9. #9
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    Lolz, when i go to the run part on my pascal compiler it says CTRL+ALT+R should make it run. Oh well.... I have alot of different attempts, I know they where all wrong. Pascal is a much easier language than C, I might learn C a bit later in my career, but im just going to stick to pascal for now.

    EDIT: I changed the hotkey to CTRL+ALT+B and now it works, lolz, thats wierd.

    EDIT: I have enchanced my code so that is now prints:
    Color=whatevercolor(x,y)
    Code:
    program ColorFinder;
    
    var color,x,y : integer;
        z,a,b: string;
    
    procedure findcolor;
    begin
         z:= '(';
         a:= ',';
         b:= ')';
         GetMousePos(x,y);
         color:=GetColor(x,y);
         writeln('color = '+IntToStr(color)+(z)+IntToStr(x)+(a)+IntToStr(y)+(b));
    end;
    begin
         findcolor;
    end.
    Last edited by wannabe723; 01-01-2009 at 08:58 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading pictures and array
    By sunoflight77 in forum C++ Programming
    Replies: 0
    Last Post: 05-09-2005, 03:16 PM
  2. question about reading in strings from a file :>
    By bball887 in forum C Programming
    Replies: 8
    Last Post: 04-13-2004, 06:24 PM
  3. question about reading files in
    By smd in forum C++ Programming
    Replies: 11
    Last Post: 08-25-2003, 07:40 PM
  4. problems reading data into an array and printing output
    By serino78 in forum C Programming
    Replies: 4
    Last Post: 04-28-2003, 08:39 AM
  5. Replies: 0
    Last Post: 07-12-2002, 01:40 PM