Reading the color of a pixel on screen

Hello again guys :smile:,

Dabbling with unity 2.6 indie now got me wondering, how can i read the colors of a certain pixel at x:y coordinates on my screen using the indie version and also doing it simply and not massacring performance.

My first thought after reading help and the forum a bit would be to link the camera to a render texture and then use the getpixel() function of the target 2d texture to get the color but that would use render textures and hence is no good when using indie

Also, i was wondering perhaps i can do a raycast from the screen space and see what i’d hit and read from it.
but no even if that works raycasting is overkill for this task.

So i hope i am missing a simple solution to this matter and that’s it’s doable

Just how can i read the color of a pixel on screen without render textures and raycasts ?

:roll:

ok i’m now looking at the Texture2D.ReadPixels function

from the documentation

function ReadPixels (source : Rect, destX : int, destY : int, recalculateMipMaps : bool = true) : void

“Description
Read screen pixels into the saved texture data.
This will copy a rectangular pixel area from the currently active RenderTexture or the view (specified by /source/) into the position defined by destX and destY. Both coordinates use pixel space - (0,0) is lower left.”

hmm, so how can the source specify a rectangle to read from EITHER a rendertexture or just the view ?

Normally you shouldn’t be reading the framebuffer, as that’s a slow operation on nearly all 3D hardware cards as far as I know, but if you really want to see how ReadPixels can be used to sample the screen…

…this doc that has a sample for taking screenshots might interest you… just skip the part where it encodes and saves to PNG…

:slight_smile:

thx cannon

i gave it a go and it answered my query

:smile: