Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为 iPad 创建一个应用程序,它可以通过检测房间的亮度来更改图像。所以我想知道有没有办法检测房间的亮度?
一种方法是获取图像中某些像素集的平均亮度。如果您有一张具有 RGB 像素的图像,您可以通过添加加权分量来获得亮度。常见的权重是 30% 红色、59% 绿色、11% 蓝色:
brightness = pixel.red * 0.3 + pixel.green * 0.59 + pixel.blue * 0.11;
根据图像的变化、您需要的测量精度、图像的分辨率等,您可以对图像周围的像素样本进行平均,或者只是对所有像素进行平均。