finding the screen coordinates of a pixel

This is a discussion on finding the screen coordinates of a pixel within the C# Programming forums, part of the General Programming Boards category; i have an image that has white pixels in it, the image is at the size of my screen, 1024x768, ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    8

    finding the screen coordinates of a pixel

    i have an image that has white pixels in it, the image is at the size of my screen, 1024x768, and i want to find the x and y coordinates of every white pixel.
    how can it be done?
    thank you in advance...

  2. #2
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    a not so elegant way would be to do a nested loop to represent x and y then do an if on each pixel at that position. you would probably want to store it in memory on a bmp first then traverse the pixels. like i said, not elegant but will get you a temp fix while you dig into the graphics stuff.

    Thats usually how i start, the quickest dirtiest way and pick up all the other techniques on the way to make it something nice.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    8
    i already tried that...
    i thought, since the picture is at the size of my screen, i would get the screen coordinates like that, but i didn't.
    i get some weird coordinates with minuses and such, dunno why...

  4. #4
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    Are you capturing the screen and storing it into a temporary BITMAP and then doing something like this:

    Code:
    Color pureWhite = Color.FromArgb(255,255,255);
    for (x = 0; x < bmap.Width; x++)
    {
        for (y = 0; y < bmap.Height; y++)
        {
            if (bmap.GetPixel(x, y) == pureWhite)
            {
                //do code whatever
             }
         }
    }
    Do you have any code, what have you tried?
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    I can't think of a more elegant solution than the given one. It's short and clear. Given that there is no knowledge about the image, there's no special knowledge that you can use to, e.g., skip parts of the image, which would be the only way of making it faster.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    well, you could grab it down then tell it to squeeze it into a forth of its size. Once squeezed, run through each pixel looking for an averaged out white and not the quadrant its in, then go back to your primary image and get the actual locations.

    doing it that way, you would possibly not catch every single pixel that was white since the compression to smaller size would average areas. But, you would most likely have less area to scan. If you wanted to catch small white area, its more likely to miss them using this method and a full scan would be the best way.

    Do you have to know the locations of the white pixels for reporting or are you just converting them or what?
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    The squeezing would take longer than just scanning the entire image.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    8
    oh, lol, my original code eventually worked, i had a stupid calculation mistake...
    thank you guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 03:56 PM
  2. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 09:18 PM
  3. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  4. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  5. Green Pixel On My Screen???
    By (TNT) in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 01-21-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