Android開發 網路攝影機自動聚焦完美實現 ————–續上

來源:互聯網
上載者:User

http://blog.csdn.net/yanzi1225627/article/details/7926994前文已經實現了自動聚焦,但末尾遺留了一個小問題。經我研究發現,是我程式裡面的自動聚焦所放的位置有問題。原來只在按下預覽按鈕,會執行initCamera,但當連續兩次按預覽後,程式就會沒有入口了。也就是第二次if(myCamera!=null
&& !isView)是不滿足的,第一次按預覽之後,myCamera對象已經對建立,且isView=true,因此我增加了一個if判斷這種情況。當myCamera建立後,且正在預覽,如果這個時候再次按下預覽,就會再次自動聚焦。源碼如下:

public void initCamera(){if(myCamera == null && !isView){myCamera = Camera.open();Log.i(TAG, "camera.open");}if(myCamera != null && !isView) {try {myParameters = myCamera.getParameters();myParameters.setPictureFormat(PixelFormat.JPEG);myParameters.setPreviewSize(1280, 720);//myParameters.setFocusMode("auto");myParameters.setPictureSize(2048, 1152); //1280, 720myParameters.set("rotation", 90);myCamera.setDisplayOrientation(90);myCamera.setParameters(myParameters);myCamera.setPreviewDisplay(mySurfaceHolder);myCamera.startPreview();isView = true;myCamera.autoFocus(mAutoFocusCallback);} catch (Exception e) {// TODO: handle exceptione.printStackTrace();Toast.makeText(TestPhotoActivity.this, "初始化相機錯誤",Toast.LENGTH_SHORT).show();}}if(myCamera != null && isView)myCamera.autoFocus(mAutoFocusCallback);}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.