1

我目前正在研究Androids Camera 2 API,我遇到了問題,我無法設置「CONTROL_AE_EXPOSURE_COMPENSATION」。如何在Android的Camera2 API中設置''CONTROL_AE_EXPOSURE_COMPENSATION''?

我的代碼:

-1.0 < exposureAdjustment < 1.0

public void setExposure(double exposureAdjustment) { 
    Range<Integer> range1 = mCameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE); 
    int minExposure = range1.getLower(); 
    int maxExposure = range1.getUpper(); 

    float newCalculatedValue = 0; 
    if (exposureAdjustment >= 0) { 
     newCalculatedValue = (float) (minExposure * exposureAdjustment); 
    } else { 
     newCalculatedValue = (float) (maxExposure * -1 * exposureAdjustment); 
    } 

    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, (int) newCalculatedValue); 
} 

可惜,這是行不通的。

回答

1

我已經找到了解決辦法,這對我的作品:

public void setExposure(double exposureAdjustment) { 
    Range<Integer> range1 = mCameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE); 
    int minExposure = range1.getLower(); 
    int maxExposure = range1.getUpper(); 

    float newCalculatedValue = 0; 
    if (exposureAdjustment >= 0) { 
     newCalculatedValue = (float) (minExposure * exposureAdjustment); 
    } else { 
     newCalculatedValue = (float) (maxExposure * -1 * exposureAdjustment); 
    } 

    try { 
     SCaptureRequest captureRequest = mSPreviewRequestBuilder.build(); 
     mSCaptureSession.setRepeatingRequest(captureRequest, camera2FocusMeteringManager.mSCaptureCallbackListener, mBackgroundHandler); 
     mSPreviewRequestBuilder.set(SCaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, (int) newCalculatedValue); 
     mSCaptureSession.capture(captureRequest, camera2FocusMeteringManager.mSCaptureCallbackListener, mBackgroundHandler); 
    } catch (CameraAccessException e) { 
     e.printStackTrace(); 
    } 
} 
相關問題