android camera setMeteringArea详解

摘要: 本文为作者原创,未经允许不得转载;原文由作者发表在博客园:http://www.cnblogs.com/panxiaochun/p/5802814.html

setMeteringArea()

android camera 类里的meteringArea可以用来设置自动白平衡和自动曝光补偿,自动对焦区域。
在此之前,我必须指出百度里关于setMeteringArea的一些错误的文章:
http://blog.csdn.net/candycat1992/article/details/21617741/
这里面的代码设计应该坑了不少人,毕竟拿来就能用,但是使用之后发现并不能准确的选择对焦区域,会跑偏。于是查阅了一下官方的说明文档。

首先,作为天朝的网民,不能用google真是个悲剧,连个官方文档都看不到,为此特意FQ才能找到准确的说明文档:
https://developer.android.com/guide/topics/media/camera.html

有梯子的可以看一下,没有的可以看这篇,这个是国内有人翻译过来了:
http://blog.csdn.net/think_soft/article/details/7998478

getMeteringAreas注释

在Android的camera类里的getMeteringAreas函数的注释是这样的:

     * <p>Gets the current metering areas. Camera driver uses these areas to
     * <p>Each metering area is a rectangle with specified weight. The
     * direction is relative to the sensor orientation, that is, what the
     * sensor sees. The direction is not affected by the rotation or
     * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
     * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
     * point. (1000, 1000) is the lower right point. 

这里面只说到-1000,-1000对应视图的左上角,1000,1000对应右下角,但是没说到是映射还是从视图中点往左上1000个像素点。所以导致了第一个链接里那份错误的代码。按照那份代码的理解,是按照视图中点分别往四个方向的1000个像素点为对焦区,超过了就没有效了。但实际是映射关系,不管屏幕的分辨率是多少,竖屏还是横屏,这1000都是映射到图像预览图上的。这在area类里面有提到:

 	* <p>The Area class is used for choosing specific metering and focus areas for
 	* <p>Each Area consists of a rectangle specifying its bounds, and a weight
 	* that determines its importance. The bounds are relative to the camera's
	* current field of view. The coordinates are mapped so that (-1000, -1000)
	* is always the top-left corner of the current field of view, and (1000,
	* 1000) is always the bottom-right corner of the current field of

实际上意思就是以下官方文档里面的图所示:
camera meteringArea

在此,我们知道点击位置后要转化成图像预览图里面的坐标再转化成1000的坐标值,再设置setMaertingArea才能正确,要不然,点击了一个亮的区域白平衡和曝光补偿没有正确调整,很大原因就是点击的坐标没有正确对应到预览图中,所以导致错误。由于预览图是不是正方形的,而设置的1000个坐标值是被拉伸了,如果要设置成正方形还要对设置的区域拉伸。

screenshot1
screenshot2
以上两个截图中红色方框中的区域是选择区域,事实证明这是对的。

posted on 2016-08-25 13:49  士多啤梨苹果橙  阅读(3599)  评论(6编辑  收藏  举报

导航