开发者

How to detect the brightness programmatically

开发者 https://www.devze.com 2023-03-07 13:01 出处:网络
I am creating an application for iPad w开发者_JAVA百科hich can change the images by detecting the brightness of the room. So I want to know is there a way to detect the brightness of the room ?One app

I am creating an application for iPad w开发者_JAVA百科hich can change the images by detecting the brightness of the room. So I want to know is there a way to detect the brightness of the room ?


One approach is to take the average brightness of some set of pixels in your image. If you have an image with RGB pixels, you can get the brightness by adding the weighted components. A common weighting is 30% red, 59% green, 11% blue:

brightness = pixel.red * 0.3 + pixel.green * 0.59 + pixel.blue * 0.11;

Depending on the variations in your image, how accurate a measure you need, the resolution of your image, etc. you can average a sample of pixels from around the image, or just average all of them.

0

精彩评论

暂无评论...
验证码 换一张
取 消