'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]
Solution 2:[2]
I suppose you can easily do this yourself:
- take a still =>
UIImage
. - convert the
UIImage
to aCGImageRef
(UIImage.CGImage
). - Now, read every pixel's color and perform such code:
x += (red + green + blue) / 3.f;
- 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 |