Share via


CameraCharacteristics.GetRecommendedStreamConfigurationMap Method

Definition

Retrieve camera device recommended stream configuration map RecommendedStreamConfigurationMap for a given use case.

[Android.Runtime.Register("getRecommendedStreamConfigurationMap", "(I)Landroid/hardware/camera2/params/RecommendedStreamConfigurationMap;", "", ApiSince=29)]
public Android.Hardware.Camera2.Params.RecommendedStreamConfigurationMap? GetRecommendedStreamConfigurationMap (Android.Hardware.Camera2.Params.UsecaseMode usecase);
[<Android.Runtime.Register("getRecommendedStreamConfigurationMap", "(I)Landroid/hardware/camera2/params/RecommendedStreamConfigurationMap;", "", ApiSince=29)>]
member this.GetRecommendedStreamConfigurationMap : Android.Hardware.Camera2.Params.UsecaseMode -> Android.Hardware.Camera2.Params.RecommendedStreamConfigurationMap

Parameters

usecase
UsecaseMode

Use case id.

Returns

Valid RecommendedStreamConfigurationMap or null in case the camera device doesn't have any recommendation for this use case or the recommended configurations are invalid.

Attributes

Remarks

Retrieve camera device recommended stream configuration map RecommendedStreamConfigurationMap for a given use case.

The stream configurations advertised here are efficient in terms of power and performance for common use cases like preview, video, snapshot, etc. The recommended maps are usually only small subsets of the exhaustive list provided in #SCALER_STREAM_CONFIGURATION_MAP and suggested for a particular use case by the camera device implementation. For further information about the expected configurations in various scenarios please refer to: <ul> <li>RecommendedStreamConfigurationMap#USECASE_PREVIEW</li> <li>RecommendedStreamConfigurationMap#USECASE_RECORD</li> <li>RecommendedStreamConfigurationMap#USECASE_VIDEO_SNAPSHOT</li> <li>RecommendedStreamConfigurationMap#USECASE_SNAPSHOT</li> <li>RecommendedStreamConfigurationMap#USECASE_RAW</li> <li>RecommendedStreamConfigurationMap#USECASE_ZSL</li> <li>RecommendedStreamConfigurationMap#USECASE_LOW_LATENCY_SNAPSHOT</li> </ul>

For example on how this can be used by camera clients to find out the maximum recommended preview and snapshot resolution, consider the following pseudo-code:

<code>
            public static Size getMaxSize(Size... sizes) {
                if (sizes == null || sizes.length == 0) {
                    throw new IllegalArgumentException("sizes was empty");
                }

                Size sz = sizes[0];
                for (Size size : sizes) {
                    if (size.getWidth() * size.getHeight() &gt; sz.getWidth() * sz.getHeight()) {
                        sz = size;
                    }
                }

                return sz;
            }

            CameraCharacteristics characteristics =
                    cameraManager.getCameraCharacteristics(cameraId);
            RecommendedStreamConfigurationMap previewConfig =
                    characteristics.getRecommendedStreamConfigurationMap(
                             RecommendedStreamConfigurationMap.USECASE_PREVIEW);
            RecommendedStreamConfigurationMap snapshotConfig =
                    characteristics.getRecommendedStreamConfigurationMap(
                             RecommendedStreamConfigurationMap.USECASE_SNAPSHOT);

            if ((previewConfig != null) &amp;&amp; (snapshotConfig != null)) {

                 Set<Size> snapshotSizeSet = snapshotConfig.getOutputSizes(
                         ImageFormat.JPEG);
                 Size[] snapshotSizes = new Size[snapshotSizeSet.size()];
                 snapshotSizes = snapshotSizeSet.toArray(snapshotSizes);
                 Size suggestedMaxJpegSize = getMaxSize(snapshotSizes);

                 Set<Size> previewSizeSet = snapshotConfig.getOutputSizes(
                         ImageFormat.PRIVATE);
                 Size[] previewSizes = new Size[previewSizeSet.size()];
                 previewSizes = previewSizeSet.toArray(previewSizes);
                 Size suggestedMaxPreviewSize = getMaxSize(previewSizes);
            }

</code>

Similar logic can be used for other use cases as well.

Support for recommended stream configurations is optional. In case there a no suggested configurations for the particular use case, please refer to #SCALER_STREAM_CONFIGURATION_MAP for the exhaustive available list.

Java documentation for android.hardware.camera2.CameraCharacteristics.getRecommendedStreamConfigurationMap(int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to