Jump to content

How to get color of pixel


daveyslc
 Share

Recommended Posts

How to get the color of a pixel at certain location on the screen?

 

For example I would like to be able to click on a map of different-colored countries at get the rgb number of the area clicked on. Something like:

 

game.getPixelColorAt(game.input.x, game.input.y)

 

note: getPixelColorAt does not exist.

 

Thanks.

 

 

Link to comment
Share on other sites

if you knew that you were drawing to a 2d canvas and not webgl you could use context.getImageData( x1, y1, x1, y1 ); the returned data will have the rgba components in it (e.g. red = imgdata.data[0])

 

but I would strongly advise you not to do this. it won't work on webgl and its performance characteristics are absolutely horrendous. it will completely blow the data flow to the GPU. basically you should avoid any *reads* from the GPU. (there is an article on optimizing graphics for google chrome that talks about this but I can't find the link at the moment). 

 

unless you are writing a paint program there is probably a better way to accomplish what you want. 

 

that said, I think you can use readPixels() in webgl to accomplish much the same thing as getImageData :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...