簡體   English   中英

如何在 Camera X 支持庫中設置曝光補償?

[英]How to set Exposure compensation in Camera X support library?

我正在使用 CameraX 庫單擊照片並想更改曝光設置。 如何設置曝光補償或更改所拍攝照片的曝光設置?

// Set up the capture use case to allow users to take photos
val imageCaptureConfig = ImageCaptureConfig.Builder().apply {
    setLensFacing(lensFacing)
    setCaptureMode(CaptureMode.MIN_LATENCY)
    // We request aspect ratio but no resolution to match preview config but letting
    // CameraX optimize for whatever specific resolution best fits requested capture mode
    setTargetAspectRatio(screenAspectRatio)
    // Set initial target rotation, we will have to call this again if rotation changes
    // during the lifecycle of this use case
    setTargetRotation(viewFinder.display.rotation)
}.build()


imageCapture = ImageCapture(imageCaptureConfig)

// Setup image analysis pipeline that computes average pixel luminance in real time
val analyzerConfig = ImageAnalysisConfig.Builder().apply {
    setLensFacing(lensFacing)
    // Use a worker thread for image analysis to prevent preview glitches
    setCallbackHandler(Handler(analyzerThread.looper))
    // In our analysis, we care more about the latest image than analyzing *every* image
    setImageReaderMode(ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
    // Set initial target rotation, we will have to call this again if rotation changes
    // during the lifecycle of this use case
    setTargetRotation(viewFinder.display.rotation)
}.build()
val imageCaptureBuilder = ImageCapture.Builder().apply {
    setLensFacing(lensFacing)
    setCaptureMode(CaptureMode.MIN_LATENCY)
    // We request aspect ratio but no resolution to match preview config but letting
    // CameraX optimize for whatever specific resolution best fits requested capture mode
    setTargetAspectRatio(screenAspectRatio)
    // Set initial target rotation, we will have to call this again if rotation changes
    // during the lifecycle of this use case
    setTargetRotation(viewFinder.display.rotation)
}

Camera2Interop.Extender(imageCaptureBuilder).setCaptureRequestOption(
  CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, exposure)
  
imageCapture = imageCaptureBuilder.build()

其中exposure是您想要的價值

理想情況下,您應該查詢CONTROL_AE_COMPENSATION_RANGE以設置exposure的有效值。

CameraX 1.0.0-beta09ExposureCompensation添加了實驗性接口

您可以通過以下方式設置曝光:

val camera = cameraProvider.bindToLifecycle(viewLifecycleOwner, cameraSelector, preview, imageCapture)
val cameraControl = camera.cameraControl
cameraControl.setExposureCompensationIndex(exposure)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM