'How to check light intensity using iPhone camera

Is there any way to check the light intensity using iPhone? Does API allows to do this?



Solution 1:[1]

Obtaining Luminosity from an iOS Camera

Solution 2:[2]

I suppose you can easily do this yourself:

  1. take a still => UIImage.
  2. convert the UIImage to a CGImageRef (UIImage.CGImage).
  3. Now, read every pixel's color and perform such code: x += (red + green + blue) / 3.f;
  4. Calculate the average brightness: avg = x / numberOfPixels;.

avg will now give you a float indicating the average brightness of the still. Most of the time (if not always), this will be identical to the light intensity.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jpulikkottil
Solution 2 cutsoy