android 摄像头亮度,[Android相机]通过手机摄像头识别环境亮度

该文章介绍了如何在Android中通过摄像头识别环境亮度,主要利用NV21格式的预览数据来计算平均亮度。通过设置Camera的PreviewCallback,获取预览帧的byte数组,计算Y值(亮度)的平均值,以此判断环境光线是否过暗。代码示例展示了具体的实现过程。
摘要由CSDN通过智能技术生成

版权声明:本文使用https://creativecommons.org/licenses/by-nc-nd/4.0/规定的《署名-非商业性使用-禁止演绎 4.0 国际》协议 https://blog.csdn.net/bluewindtalker/article/details/79999172

本篇文章即为通过一系列的方法获得当前摄像头所处环境的亮度,最相近的就是微信的扫一扫提示“轻触照亮”打开手电筒的功能,首先我们看一个方法setPreviewFormat方法,在注释中我们可以清楚的看到默认使用NV21格式,

/**

* Sets the image format for preview pictures.

*

If this is never called, the default format will be

* {@link android.graphics.ImageFormat#NV21}, which

* uses the NV21 encoding format.

*

* 此处省略部分内容

*

* @param pixel_format the desired preview picture format, defined by

* one of the {@link android.graphics.ImageFormat} constants. (E.g.,

* ImageFormat.NV21 (default), or

* ImageFormat.YV12)

*

* @see android.graphics.ImageFormat

* @see android.hardware.Camera.Parameters#getSupportedPreviewForm

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值