How to check light intensity using iPhone camera

前端 未结 2 1417
Happy的楠姐
Happy的楠姐 2021-02-07 10:06

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

相关标签:
2条回答
  • 2021-02-07 10:30

    Obtaining Luminosity from an iOS Camera

    0 讨论(0)
  • 2021-02-07 10:48

    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.

    0 讨论(0)
提交回复
热议问题