How to detect the brightness programmatically
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.
精彩评论