c# - Getting brightness of displayed screen or of a Texture2D - Unity3D -
in project, need brightness of screen being displayed. that, snapshot of screen , make texture2d
to snapshot , convert use this:
public void getscreen(ref texture2d screenshot){ rendertexture rt = new rendertexture(screen.width, screen.height, 24); camera.targettexture = rt; screenshot = new texture2d(screen.width, screen.height, textureformat.rgb24, false); camera.render(); rendertexture.active = rt; screenshot.readpixels(new rect(0, 0, sreen.width, screen.height), 0, 0); camera.targettexture = null; rendertexture.active = null; destroy(rt); }
but still need brightness.
suggestions accepted (about brightness and/or conversion).
in advance.
once have pixels, next step use pixels on image sample of them , build brightness them: http://docs.unity3d.com/documentation/scriptreference/texture2d.getpixel.html
determining brightness bit of complex issue, depends on application. formula determine brightness of rgb color has methods determine brightness of single pixel. sample several pixels towards center of image, , take average of those.
if need more complex solution, build histogram of pixels brightness, , find peak. http://en.wikipedia.org/wiki/image_histogram .
Comments
Post a Comment