低光源增強

Android 15 推出了低光源增強,這是全新的自動曝光模式, 相機 2夜間模式相機擴充功能。低光源增強 在低光源環境下,自動調整預覽串流的亮度 條件。這與夜間模式相機擴充功能產生的方式不同 因為夜間模式會結合多張相片 修飾圖片雖然夜間模式非常適合用來拍攝靜態圖像 低亮度增強功能可以連續播放影格串流。因此, 低光源強化系統提供全新相機功能,例如:

  • 提供修飾後的圖片預覽,讓使用者更好地畫框 在低光源環境下拍照。
  • 正在低光源環境掃描 QR code。

如果你啟用低光源增強,這項功能會在低光源環境時自動開啟 ,並在光線增加時關閉。

應用程式可在低光源環境下關閉預覽串流,以便儲存 影片調亮。

低光源強化:您可以使用 Camera2攝影機擴充功能。 本文件說明如何搭配 Camera2 使用低光源強化功能。您也可以使用 低光源強化:搭配夜間模式相機擴充功能 (如果支援的話) 裝置。

查詢空房

使用低光源增強前,請先確認裝置支援這項功能。如果是 可用時,低光源增強是列於 camera2.CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES。(低光源 因為其他自動曝光設定,強化器本身即是自動曝光設定 與低光源增強效果所做的預覽調光不相容)。

如果需要確認是否可以使用「低光源增強」功能,請撥打 CameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES)敬上 然後檢查傳回的模式是否包含 ON_LOW_LIGHT_BOOST_BRIGHTNESS_PRIORITY

Kotlin

val characteristics = cameraManager.getCameraCharacteristics(cameraId)
val autoExposureModes =
    characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES)!!
val lowLightBoostSupported = autoExposureModes.contains(
        CameraMetadata.CONTROL_AE_MODE_ON_LOW_LIGHT_BOOST_BRIGHTNESS_PRIORITY)

if (lowLightBoostSupported) {
  // Enable Low Light Boost (next section)
} else {
  // Proceed without Low Light Boost
}

Java

CameraCharacteristics characteristics =
    mCameraManager.getCameraCharacteristics(cameraId);
int[] autoExposureModes =
    characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES);
boolean lowLightBoostSupported = autoExposureModes.contains(
        CameraMetadata.CONTROL_AE_MODE_ON_LOW_LIGHT_BOOST_BRIGHTNESS_PRIORITY);

if (lowLightBoostSupported) {
  // Enable Low Light Boost (next section)
} else {
  // Proceed without Low Light Boost
}

啟用低光源增強

如要在 Camera2 工作階段中啟用低光源強化功能,請 CaptureRequest.CONTROL_AE_MODEON_LOW_LIGHT_BOOST_BRIGHTNESS_PRIORITY。完成之後,您需要 確認低光源增強已開啟。就可以查看 CaptureResult.CONTROL_AE_MODE 欄位。由於低光源環境,你需要檢查裝置 強化器與所有相機設定不相容。例如:高速 基於 FPS 考量,錄製功能不支援低光源增強。如果 低光源增強功能未開啟,你可能需要更換攝影機 設定,然後再試一次

Kotlin

val captureRequestBuilder = camera.createCaptureRequest(
  CameraDevice.TEMPLATE_PREVIEW)
if (isLowLightBoostAvailable(cameraId)) {
  captureRequestBuilder.set(
    CaptureRequest.CONTROL_AE_MODE,
    CameraMetadata.CONTROL_AE_MODE_ON_LOW_LIGHT_BOOST_BRIGHTNESS_PRIORITY
  )
}
// other capture request params

session.setRepeatingRequest(
  captureRequestBuilder.build(),
  object : CaptureCallback() {
    @Override
    fun onCaptureCompleted(session: CameraCaptureSession,
        request: CaptureRequest, result: TotalCaptureResult) {
      // verify Low Light Boost AE mode set successfully
      result.get(CaptureResult.CONTROL_AE_MODE) ==
          CameraMetadata.CONTROL_AE_MODE_ON_LOW_LIGHT_BOOST_BRIGHTNESS_PRIORITY
    }
  },
  cameraHandler
)

Java

CaptureRequest.Builder captureRequestBuilder =
  mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
if (isLowLightBoostAvailable(cameraId)) {
  captureRequestBuilder.set(
    CaptureRequest.CONTROL_AE_MODE,
    CameraMetadata.CONTROL_AE_MODE_ON_LOW_LIGHT_BOOST_BRIGHTNESS_PRIORITY);
}
// other capture request params

mSession.setRepeatingRequest(
  captureRequestBuilder.build(),
  new CaptureCallback() {
    @Override
    public void onCaptureCompleted(CameraCaptureSession session,
        CaptureRequest request, TotalCaptureResult result) {
      // verify Low Light Boost AE mode set successfully
      result.get(CaptureResult.CONTROL_AE_MODE) ==
          CameraMetadata.CONTROL_AE_MODE_ON_LOW_LIGHT_BOOST_BRIGHTNESS_PRIORITY;
    }
  },
  mCameraHandler
);

監控低光源模式

低光源強化功能會在低光源環境下提高預覽串流亮度,且 如果環境已亮度足夠正常,就不會有任何效果 擷取。如要確認低光源模式是否已啟用,請查看 CaptureResult.CONTROL_LOW_LIGHT_BOOST_STATE 欄位。開啟通知後 低光源強化為目前狀態,且該欄位已設為 CameraMetadata.CONTROL_LOW_LIGHT_BOOST_STATE_ACTIVE。 此時可能會顯示 月亮圖示或其他指標,表示預覽畫面正在增加亮度。

Kotlin

session.setRepeatingRequest(
  captureRequestBuilder.build(),
  object : CaptureCallback() {
    @Override
    fun onCaptureCompleted(session: CameraCaptureSession,
        request: CaptureRequest, result: TotalCaptureResult) {
      // check if Low Light Boost is active or inactive
      if (result.get(CaptureResult.CONTROL_LOW_LIGHT_BOOST_STATE) ==
        CameraMetadata.CONTROL_LOW_LIGHT_BOOST_STATE_ACTIVE) {
        // Low Light Boost state is active
        // Show Moon Icon
      } else {
        // Low Light Boost state is inactive or AE mode is not set
        // to Low Light Boost
        // Hide Moon Icon
      }
    }
  },
  cameraHandler
)

Java

mSession.setRepeatingRequest(
  captureRequestBuilder.build(),
  new CaptureCallback() {
    @Override
    public void onCaptureCompleted(CameraCaptureSession session,
        CaptureRequest request, TotalCaptureResult result) {
      // check if Low Light Boost is active or inactive
      if (result.get(CaptureResult.CONTROL_LOW_LIGHT_BOOST_STATE) ==
        CameraMetadata.CONTROL_LOW_LIGHT_BOOST_STATE_ACTIVE) {
        // Low Light Boost state is active
        // Show Moon Icon
      } else {
        // Low Light Boost state is inactive or AE mode is not set
        // to Low Light Boost
        // Hide Moon Icon
      }
    }
  },
  mCameraHandler
);