help on pixels

This is a discussion on help on pixels within the Windows Programming forums, part of the Platform Specific Boards category; i'm kinda a noob but i know the basics of windows programming and c++. what i'm trying to figure out ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    67

    help on pixels

    i'm kinda a noob but i know the basics of windows programming and c++. what i'm trying to figure out is how to use GetPixel without getting a lot of errors. i'm trying to make a small program that gets the color of a pixel and simply print it out. but i can't find a working example anywhere. can someone give me some help.

    also plz don't refer me to msdn i've gone there but thats no help to a beginner. that just defines it it doesn't show how to use it.
    Last edited by bballzone; 07-08-2004 at 08:27 AM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    There's a small example in this thread which gets the pixel value at the current cursor position. A board search should give some more information/examples.

    >>how to use GetPixel without getting a lot of errors<<

    It makes it much easier for us to help you if you post the problematic code and any errors you're getting.

    >>don't refer me to msdn i've gone there but thats no help to a beginner<<

    Although it can be somewhat daunting at first stick with msdn; your perseverance will be rewarded.

    Welcome to the boards.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    thx for the welcome

    "It makes it much easier for us to help you if you post the problematic code and any errors you're getting."

    ok i used that code in that other topic. i copied and pasted it into a new file and compiled it. thats all thats in there. i get the following errors.

    COLORREF clr;
    getpixel.cpp<2>: Error: missing decl-specifier-seq for declaration of 'COLORREF'

    HDC hdcScrn;
    getpixel.cpp<3>: Error: missing decl-specifier-seq for declaration of 'HDC

    getpixel.cpp<4>: Error: missing decl-specifier-seq for declaration of 'POINT'

    GetCursorPos<&pt>;
    getpixel.cpp<6>: Error: missing decl-specifier-seq for declaration of 'GetCursorPos'

    hdcScrn=CreateDC<"DISPLAY",0,0,0>;

    getpixel.cpp<7>: Error: missing decl-specifier-seq for declaration of 'hdcScrn'


    the error weren't copied and pasted because they were in my command prompt so any spelling errors are on me. but this is a start i guess. i don't know what the errors mean at all or how to fix them. i'm guessing i need to include code lines but i'm gonna take it one step at a time.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    #include <windows.h>

    You need to include that header before you start using things from it.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    new errors...but less is good


    getpixel.obj<getpixel>
    Error 42: Symbol Undefined _DeleteDC@4
    getpixel.obj<getpixel>
    Error 42: Symbol Undefined _GetPixel1@12
    getpixel.obj<getpixel>
    Error 42: Symbol Undefined _CreateDCA@16

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You have to link to the gdi32.lib library.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  7. #7
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    how do i do that?

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Depends on your compiler. You should consult the documentation or tell us what compiler you use.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  9. #9
    Registered User
    Join Date
    Jul 2004
    Posts
    14
    http://www.henkessoft.de/WinAPI_7_GDI.htm

    Look at the GDI-programs (script is in German). Perhaps they might help you understanding GDI.

  10. #10
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    my compiler - Digital Mars C/C++ Compilers
    i have dev-c++ also but i don't use it cuz i get more errors but when i compile the same code with DM it compiles.

    thx for the link it looks like the stuff i'm looking for. to google to translate...

  11. #11
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    try adding

    Code:
    #pragma comment(lib, "gdi32.lib")
    by the windows header include, i have not heard of that compiler but i tried that in vc after removing it from my link list in the project settings and it still ran.

    also i am using GetPixel, you can kinda see how it works a little bit i posted my code in
    Webcam Image Capture
    i am using the info for processing but in my example you can just use the values it returns to print out or whatever.

    hope this helps
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  12. #12
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    thx now it compiles with no errors

    now all i have to do is make this

    #include <windows.h>
    #pragma comment(lib, "gdi32.lib")

    int main()
    {
    COLORREF clr;
    HDC hdcScrn;
    POINT pt;

    GetCursorPos(&pt);
    hdcScrn=CreateDC("DISPLAY",0,0,0);
    clr=GetPixel(hdcScrn,pt.x,pt.y);
    DeleteDC(hdcScrn);

    return 0;
    }

    print out the color value...seems easy enough

  13. #13
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    dont forget to break down the colorref value into the red green and blue values because the colorref value is just a hex value and there are macros to grab those hex values and turn them into bits so you can display them.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  14. #14
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    oh yeah those macros are GetRValue() GetBValue() and GetGValue() and you can use them something like this.

    Code:
    COLORREF pixColor = GetPixel(someHdc,13,13);
    char chPixColor[1024];
    sprintf(chPixColor,"R=%d G=%d B=%d",GetRValue(pixColor),GetGValue(pixColor),GetBValue(pixColor));
    MessageBox(hwnd,chPixColor,"Pixel Color @ x=13 y=13",0);
    but you probably already knew that.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  15. #15
    Registered User
    Join Date
    Jul 2004
    Posts
    67
    dang now i have to figure out how to do that lol

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Manipulating single LCD pixels
    By finnepower in forum Networking/Device Communication
    Replies: 3
    Last Post: 02-22-2008, 07:45 PM
  2. Trying to write individual pixels to the screen
    By IanC in forum C++ Programming
    Replies: 3
    Last Post: 04-14-2004, 12:49 PM
  3. bitmap pixels???????????
    By SuperNewbie in forum Windows Programming
    Replies: 2
    Last Post: 03-23-2004, 12:53 AM
  4. creating image from pixels stored in file
    By Kristian25 in forum Windows Programming
    Replies: 3
    Last Post: 01-21-2003, 01:08 PM
  5. Algo needed for 'Fit to page'
    By Unregged in forum Windows Programming
    Replies: 6
    Last Post: 10-03-2002, 07:09 AM

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