setTargetAspectRatio and setTargetResolution are Deprecated

314 views
Skip to first unread message

Jakub Bober

unread,
May 27, 2023, 8:12:23 AM5/27/23
to Android CameraX Discussion Group
Welcome

I have this code

imageCapture = ImageCapture.Builder()
.apply {
this.setTargetRotation(orientation)

if ( actualCameraIsFormat16_9 ) {
this.setTargetAspectRatio(AspectRatio.RATIO_16_9)
///AspectRatio.RATIO_4_3
} else {
this.setTargetResolution(Size(width, height))
}

if ( actualCameraIsMaxQuality ) {
this.setCaptureMode(ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY)
}

this.setFlashMode(flashLamp)
}
.build()


it show setTargetAspectRatio and setTargetResolution are Deprecated

How to use ResolutionSelector with AspectRatioStrategy to specify the preferred aspect ratio?


Charcoal Chen

unread,
May 28, 2023, 9:27:04 PM5/28/23
to Jakub Bober, Android CameraX Discussion Group
Hi,

Please see the following sample code:

val imageCapture = ImageCapture.Builder()
.apply {
this.setTargetRotation(orientation)

// Updated part begin

val resolutionSelectorBuilder = ResolutionSelector.Builder().apply {
if (actualCameraIsFormat16_9) {
setAspectRatioStrategy(AspectRatioStrategy.RATIO_16_9_FALLBACK_AUTO_STRATEGY)
} else {
setResolutionStrategy(
ResolutionStrategy(
Size(
widthInSensorOrientation,
heightInSensorOrientation
), ResolutionStrategy.FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER
)
)
}
}

this.setResolutionSelector(resolutionSelectorBuilder.build())

// Updated part end

if (actualCameraIsMaxQuality) {
this.setCaptureMode(ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY)
}

this.setFlashMode(flashLamp)
}
.build()

Please note that the size used to create the ResolutionStrategy is the size expressed in the sensor coordinate orientation that is the same as the output sizes retrieved via StreamConfigurationMap#getOutputSizes(int).



--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/4fd9c6bd-8614-4d55-b229-85b6cddd9b70n%40android.com.
Reply all
Reply to author
Forward
0 new messages