简体   繁体   English

如何使用iPhone相机检查光强度

[英]How to check light intensity using iPhone camera

Is there any way to check the light intensity using iPhone? 有没有办法用iPhone检查光强度? Does API allows to do this? API是否允许这样做?

I suppose you can easily do this yourself: 我想你可以自己轻松做到这一点:

  1. take a still => UIImage . 拿一个静止=> UIImage
  2. convert the UIImage to a CGImageRef ( UIImage.CGImage ). UIImage转换为CGImageRefUIImage.CGImage )。
  3. Now, read every pixel's color and perform such code: x += (red + green + blue) / 3.f; 现在,读取每个像素的颜色并执行以下代码: x += (red + green + blue) / 3.f;
  4. Calculate the average brightness: avg = x / numberOfPixels; 计算平均亮度: avg = x / numberOfPixels; .

avg will now give you a float indicating the average brightness of the still. avg现在会给你一个浮动,指示静止的平均亮度。 Most of the time (if not always), this will be identical to the light intensity. 大多数时候(如果不总是),这将与光强度相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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