读取 iPhone 的环境光传感器
我注意到我的 iPhone 上,在阳光直射几秒钟后,屏幕会调整为更亮、更暗等。我想知道是否有办法与这个传感器交互?
我有一个在外面使用的应用程序。当您进入直射光时,在调整之前的一段时间内很难看清屏幕。即便如此,它并不总是像我希望的那样明亮。我想为室外观看实现高对比度皮肤,为室内观看实现低对比度。
是否可以读取光传感器数据?如果可以,如何提取这些传感器值?
不过,我假设有一个光传感器,因为相机知道何时使用闪光灯。
I notice on my iPhone, after a few seconds of being in direct sun light, the screen will adjust to become brighter, dimmer etc. I was wondering if there was a way to interact with this sensor?
I have an application which is used outside. When you go into direct light, it becomes very difficult to see the screen for a few momments, before it adjusts. And even then, it's not always as bright as I'd like it to be. I would like to implement a high contrast skin for outdoor viewing, and a low contrast for indoor viewing.
Is this possible to read light sensor data, and if so, how do I extract these sensor values?
I would assume there is a light sensor however, as the camera knows when to use the flash.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
另一方面,这是一个不同的想法(也许是一个愚蠢的想法),使用设备屏幕的亮度,您可以获得外部条件的一些值。
从 0.12(深色)到 0.99(浅色)
下一行将获取这些值,尝试一下,在设备上打开和关闭一些灯以获得不同的值。
显然,应该打开自动亮度功能才能使其正常工作。
问候。
On the other hand this is a different idea (maybe a silly one), using the brightness of the device's screen you can get some value of the external conditions.
From 0.12 (Dark) to 0.99 (Light)
The next line will get those values, give it a try, put some light on and off over the device to get different values.
Obviously Automatic Brightness feature should be turned on in order to get this to work.
Regards.
要读取环境光传感器数据,需要使用IOKit框架中的IOHID。
http://iphonedevwiki.net/index.php/AppleISL29003
http://iphonedevwiki.net/index.php/IOKit.framework
但是,这需要私有标头,所以如果您使用它,苹果可能不会让你的应用进入应用商店。
我不断询问iOS论坛未来是否支持环境光传感器读数,但没有结果。
To read the ambient light sensor data, you need to use IOHID in the IOKit framework.
http://iphonedevwiki.net/index.php/AppleISL29003
http://iphonedevwiki.net/index.php/IOKit.framework
However, this requires private headers, so if you use it, Apple probably won't let your app into the app store.
I continually ask the iOS forums whether there will be support for ambient light sensor readings in the future, but to no avail.
您实际上可以使用相机来执行此操作,这与用户的屏幕亮度设置无关(即使“自动亮度”关闭也可以工作)。
您可以从视频帧的元数据中读取亮度值,正如我在此 Stack Overflow 答案中所解释的那样。
You can actually use the camera to do this, which is independent of the user's screen brightness settings (and works even if Automatic Brightness is OFF).
You read the Brightness Value from the video frames' metadata as I explain in this Stack Overflow answer.
尝试使用
GSEventSetBacklightLevel();
,这需要
。这就是如何以编程方式调整亮度级别。还有一个get
选项,所以我认为它可能包含您想要的信息。Try using
GSEventSetBacklightLevel();
, which requires<GraphicsServices/GraphicsServices.h>
. This is how one can programmatically adjust the brightness levels. There is also aget
option, so I think that may have the information you're after.对于 iOS 14 及更高版本,Apple 提供了 SensorKit ( https://developer.apple.com/documentation/sensorkit/srsensor/3377673-ambientlightsensor )用于显式访问各种传感器和系统日志(通话记录、消息日志等)。除了原始勒克斯值之外,您还可以获得环境光的色度以及相对于设备传感器的方向。
(来自 https://developer.apple.com/documentation/sensorkit/srambientlightsample )
但是,您需要请求批准此类应用程序才能被接受并在 App Store 上发布。
For iOS 14 and above, Apple has provided SensorKit (https://developer.apple.com/documentation/sensorkit/srsensor/3377673-ambientlightsensor ) for explicit access to all kinds of sensors and system logs (call logs, message logs, etc.). In addition to the raw lux value, you can also get the chromaticity of the ambient light and the orientation relative to the device sensor.
(From https://developer.apple.com/documentation/sensorkit/srambientlightsample )
However, you need to request for approval for such an App to be accepted and published on App Store.
对于 Swift 5,以下是如何使用亮度检测来间接提供外部亮度:
For Swift 5, here is how to use the brightness detection which indirectly gives you the luminosity of the outside: