2017-10-12 62 views
0

我已經實現圖像連續捕捉與camera2的API,其優良的工作人員採取6 fps..bt我的問題是,當它拍照它trigers對焦鎖定這就是爲什麼預覽被鎖定的時間的一小ammount的,我想刪除預覽鎖,我想預覽始終啓用,這是我的靜像拍攝一陣,我下面谷歌camera2例如預覽鎖定,同時捕獲圖像camera2

private void captuteStillImage() { 
    try { 
     count = 0; 
     CaptureRequest.Builder captureBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); 

     int rotation = getWindowManager().getDefaultDisplay().getRotation(); 
     captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation)); 

     CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() { 
      @Override 
      public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) { 
       super.onCaptureCompleted(session, request, result); 
       //unlockFocus(); 
       count++; 
       Log.e("count",count+""); 
       runOnUiThread(new Runnable() { 
       @Override 
       public void run() { 
        tv_count.setText(count+""); 

       } 
      }); 

       if (count >= MAX_CAPTURE) { 
        unlockFocus(); 
       } 
       Log.e("Image Capture", "Successfully"); 
      } 
     }; 

     // mCameraCaptureSession.capture(captureBuilder.build(), captureCallback, null); 

     List<CaptureRequest> captureList = new ArrayList<CaptureRequest>(); 
     captureBuilder.addTarget(mImageReader.getSurface()); 
     for (int i = 0; i < MAX_CAPTURE; i++) { 
      captureList.add(captureBuilder.build()); 
     } 
     //mCameraCaptureSession.stopRepeating(); 
     mCameraCaptureSession.captureBurst(captureList, captureCallback, null); 
    } catch (CameraAccessException e) { 
     e.printStackTrace(); 
    } 
} 

回答

1

我對camera2basic(https://github.com/googlesamples/android-Camera2Basic)實驗一小本,發現我能拿預覽返回快得多,如果我只是獲取圖像後保存之前叫做解鎖 - 我也刪除在captureCallback原始呼叫轉接給unlockFocus方法。

/** 
    * This a callback object for the {@link ImageReader}. "onImageAvailable" will be called when a 
    * still image is ready to be saved. 
    */ 
    private final ImageReader.OnImageAvailableListener mOnImageAvailableListener 
      = new ImageReader.OnImageAvailableListener() { 

     @Override 
     public void onImageAvailable(ImageReader reader) { 
      Log.d(TAG,"onImageAvailable"); 

      //Get the image 
      Image cameraImage = reader.acquireNextImage(); 

      //Now unlock the focus so the UI does not look locked - note that this is a much earlier point than in the 
      //original Camera2Basic example from google as the original place was causing the preview to lock during any 
      //image manipulation and saving. 
      unlockFocus(); 

      //Save the image file in the background - note check you have permissions granted by user or this will cause an exception. 
      mBackgroundHandler.post(new ImageSaver(getActivity().getApplicationContext(), cameraImage, outputPicFile); 

     } 

    }; 

然而,Camera2Basic有很多回調,我發現,當你開始使用情況的測試,其中活動或片段的暫停和恢復,特別是如果你的應用程序有其他的異步回調還,這是很容易進入可能導致意外行爲或崩潰的競賽狀況。

如果你只是想拍照時,返回預覽更快的相機的一個簡單的例子,那麼基本FotoApparat例子可能是值得考慮的還有:

+0

我可以不保存圖像文件從閱讀器獲得,因爲它會關閉新形象captured..I我captureing 6圖像爆的話,我有。試過,我試圖圖像時的拍攝完成,然後試圖保存逐一保存在數組然後BT崩潰爲圖像已經關閉@Mick –