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真是個悲劇,連個官方文檔都看不到,為此特意翻牆才能找到准確的說明文檔:
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
以上兩個截圖中紅色方框中的區域是選擇區域,事實證明這是對的。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM