简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM