2016-12-05 118 views
1

我有一個Android應用程序,可輕鬆聚焦功能。它適用於我嘗試過的所有手機(Nexus 5X,三星Galaxy S7,華碩ZenFone 3 Deluxe),但Google Pixel除外。Camera2 API焦點不適用於Google Pixel

這裏是代碼我使用時,用戶點擊屏幕:

public void focusAt(Point point) { 

    try { 
     // compute metering rectangle from the focus point 
     // see here: https://github.com/PkmX/lcamera/blob/master/src/pkmx/lcamera/MainActivity.scala (from line 759) 
     int meteringRectangleSize = 300; 
     int left = activeArraySize.left; 
     int right = activeArraySize.right; 
     int top = activeArraySize.top; 
     int bottom = activeArraySize.bottom; 

     float x = (float)point.x/mPreviewSize.getWidth(); 
     float y = (float)point.y/mPreviewSize.getHeight(); 

     MeteringRectangle rectangle = new MeteringRectangle(
       Math.max(0, Math.round(left + (right - left) * y - meteringRectangleSize/2)), 
       Math.max(0, Math.round(bottom - (bottom - top) * x - meteringRectangleSize/2)), 
       meteringRectangleSize, 
       meteringRectangleSize, 
       1 
     ); 

     // create a new capture request 
     mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); 

     // set the Auto focus mode to auto and set the region computed earlier 
     mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO); 
     mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START); 
     mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[]{rectangle}); 

     // add the preview surface as a target and start the request 
     mPreviewBuilder.addTarget(previewSurface); 
     mPreviewSession.capture(mPreviewBuilder.build(), null, mBackgroundHandler); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

上發生了什麼事情上的像素任何想法?

EDI:我activeArraySize這樣:

CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); 
String cameraId = manager.getCameraIdList()[0]; 
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); 
activeArraySize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); 

回答

1

你在隨後的重複要求離開AF_MODE爲AUTO和AF_REGIONS爲{}矩形,以及?

如果他們只在觸發請求中設置爲AUTO,那麼您可能會立即將自動對焦重置爲CONTINUOUS_PICTURE/no區域或您的重複請求設置爲。

因此,請確保您已將AF_MODE設置爲AUTO並將AF_REGIONS設置爲用於重複請求的{rectangle},但不要將AF_TRIGGER設置爲START多於一次capture()調用。

+0

感謝您的回答,但是我的後續重複請求是什麼意思? –

+0

在這段代碼片段中,您提交了一個捕獲請求來觸發觸摸到焦點。你如何在此之外運行你的預覽? –