0

In my project, I need to get the brightness of the screen that is being displayed. to do that, I get a snapshot of the screen and make it as a Texture2D

To get the snapshot and convert it I 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 I still need to get the brightness.
Any suggestions will be accepted (about the brightness and/or about the conversion).
Thanks in advance.

Victor__
  • 97
  • 1
  • 9

1 Answers1

0

Once you have the pixels, the next step is to use get pixels on the image to sample some of them and build the brightness from them: http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.GetPixel.html

Determining brightness is a bit of a complex issue, so it really depends on your application. Formula to determine brightness of RGB color has methods to determine the brightness of a single pixel. You could sample several pixels towards the center of your image, and then take the average of those.

If you need a more complex solution, you could build a histogram of all the pixels brightness, and then find the peak. http://en.wikipedia.org/wiki/Image_histogram .

Community
  • 1
  • 1
jonbro
  • 353
  • 2
  • 10