Pixel's

This is a discussion on Pixel's within the C++ Programming forums, part of the General Programming Boards category; Im making a program that will search for a certain color and log its position i have no idea how ...

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    Pixel's

    Im making a program that will search for a certain color and log its position i have no idea how i would go about doing this could anyone give me some hints ive found
    Code:
    GetPixel();
    but are having no luck

    Code:
    #define WHITE_BALL RGB (0, 0, 0)
    if (GetPixel(hDc, 200,200) == WHITE_BALL)

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>#define WHITE_BALL RGB (0, 0, 0)
    White is RGB(255,255,255) just so you know.

    If you want to search, then do a search. Assuming GetPixel() is operating as expected, an easy solution would be to loop through all pixels using a nested for loop, testing for white.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Maybe creating a 2D array to hold the pixel data and such, then sift through a nested for loop(like Hunter2 suggested) to test for white. Also hun: in RGB, 0-0-0 is black...Although I don't really know much about the function RGB, I'm assuming it takes in the 3 parameters for each color....and 0 of each is black. You'd want something like (depending on what kind of paramters RBG() takes cause I don't know) 1, 255, FF, or something along those lines.

    In addition to that, I like to be the grammar police some times... One of my grand pet peeves is someone using contractions in speech out of place. You realize that "Pixel's" is the contraction of "Pixel" and "is", yes? ....Well, no one's perfect...but that sort of grammar error kind of irritates me. Maybe I just gave you a helpful grammar lesson that you can take with you in life: Unless it's showing posession (The pixel's color) or is a contraction (The pixel's eating cheese), don't use an apostrophe.

    This has been a friendly grammar lesson from Dean.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    In addition to that, I like to be the grammar police some times... One of my grand pet peeves is someone using contractions in speech out of place. You realize that "Pixel's" is the contraction of "Pixel" and "is", yes? ....Well, no one's perfect...but that sort of grammar error kind of irritates me. Maybe I just gave you a helpful grammar lesson that you can take with you in life: Unless it's showing posession (The pixel's color) or is a contraction (The pixel's eating cheese), don't use an apostrophe.

    This has been a friendly grammar lesson from Dean.
    You can't be serious. Maybe you've been smoking too much of your user name. This is not a grammar board nor an english board. Get over it and keep your comments relative to um...well...C++ programming.


    As for the question. I'm assuming you have a COLORREF pointer to the buffer that has the color information in it.

    Code:
    struct PixelInformation
    {
      COLORREF Color;
      CPoint Position;
      PixelInformation *Next;
      PixelInformation *Prev;
    
      PixelInformation(void):Color(0),Position(CPoint(0,0)),Next(NULL),Prev(NULL) {}
    };
    
    void FindPixelsWithColor(COLORREF ColorToSearchFor,COLORREF *Buffer,int BufferWidth,DWORD BufferSize,PixelInformation &Root)
    {
      DWORD offset=0;
      DWORD color=0;
      int x=0,y=0;
      DWORD MatchingPixels=0;
      DWORD PixelColor=0;
      PixelInformation *CurPixel;
      
      for (offset=0;offset<BufferSize;i++)
      {
         PixelColor=Buffer[offset];
         if (PixelColor==ColorToSearchFor)
         {
            if (MatchingPixels==0)
            {
               Root.Color=PixelColor;
               Root.Position.x=x;
               Root.Position.y=y;
               Root.Position.Prev=NULL;
               Root.Next=NULL;
               *CurPixel=Root;
               MatchingPixels++;
            }
            else
            {
               PixelInformation *pixel=new PixelInformation;
               CurPixel->Next=pixel;
               pixel->Prev=CurPixel;
               pixel->Next=NULL;
               pixel->Color=PixelColor;
               pixel->Position.x=x;
               pixel->Position.y=y;
               
               CurPixel=pixel;
               MatchingPixels++;
             }
         
           x++;
           if (x>BufferWidth)
           {
              x=0;
              y++;
           }
         }
      }    
    }

    If this doesn't compile check the pointer usage. I did not test it so I'm not sure I'm using them correctly. This will assemble a double linked list of pixels that match the given color. Each pixel is linked to the previous and next in the list. I would have to compile it and see what happened in order to get it perfect.

    But this should work.

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