public class

ResolutionInfo

extends java.lang.Object

 java.lang.Object

↳androidx.camera.core.ResolutionInfo

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-core', version: '1.5.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-core
  • version: 1.5.0-alpha01

Artifact androidx.camera:camera-core:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

A ResolutionInfo allows the application to know the resolution information of a specific use case.

Applications can know the resolution information of Preview before a SurfaceRequest is received, or know the resolution information of ImageAnalysis before an ImageProxy is received from ImageAnalysis.Analyzer.

Summary

Constructors
publicResolutionInfo(Size resolution, Rect cropRect, int rotationDegrees)

Creates a new instance of ResolutionInfo with the given parameters.

Methods
public booleanequals(java.lang.Object obj)

public RectgetCropRect()

Returns the crop rectangle.

public SizegetResolution()

Returns the output resolution used for the use case.

public intgetRotationDegrees()

Returns the rotation degrees needed to transform the output resolution to the target rotation.

public inthashCode()

public java.lang.StringtoString()

from java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait

Constructors

public ResolutionInfo(Size resolution, Rect cropRect, int rotationDegrees)

Creates a new instance of ResolutionInfo with the given parameters. This constructor is not normally needed outside of testing cases.

Parameters:

resolution: The resolution used for the UseCase expressed in the coordinates of the camera sensor.
cropRect: The crop rectangle specifies the region of valid pixels in the buffer.
rotationDegrees: The clockwise rotation in degrees that needs to be applied to the output buffer so the image appears upright at the target rotation setting.

See also: ResolutionInfo.getResolution(), ResolutionInfo.getCropRect(), ResolutionInfo.getRotationDegrees()

Methods

public Size getResolution()

Returns the output resolution used for the use case.

The resolution will be expressed in the coordinates of the camera sensor. The dimensions need to be flipped by the rotation degrees obtained via ResolutionInfo.getRotationDegrees() to match the target rotation setting.

public Rect getCropRect()

Returns the crop rectangle.

The crop rectangle specifies the region of valid pixels in the buffer, using coordinates from (0, 0) to the (width, height) of the resolution obtained by ResolutionInfo.getResolution(). The dimensions need to be flipped by the rotation degrees obtained via ResolutionInfo.getRotationDegrees() to match the target rotation setting.

If the use case is configured with a ViewPort, this value is calculated based on the configuration of ViewPort; if not, it returns the full rect of the buffer which the dimensions will be the same as the value obtained from ResolutionInfo.getResolution().

public int getRotationDegrees()

Returns the rotation degrees needed to transform the output resolution to the target rotation.

This is a clockwise rotation in degrees that needs to be applied to the output buffer so the image appears upright at the target rotation setting. The rotation will be determined by the camera sensor orientation value and target rotation setting.

Returns:

The rotation in degrees which will be a value in {0, 90, 180, 270}.

public int hashCode()

public boolean equals(java.lang.Object obj)

public java.lang.String toString()

Source

/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.camera.core;

import android.graphics.Rect;
import android.util.Size;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.camera.core.impl.ImageOutputConfig;

import com.google.auto.value.AutoValue;

/**
 * A {@link ResolutionInfo} allows the application to know the resolution information of a
 * specific use case.
 *
 * <p>Applications can know the resolution information of {@link Preview} before a
 * {@link SurfaceRequest} is received, or know the resolution information of
 * {@link ImageAnalysis} before an {@link ImageProxy} is received from
 * {@link ImageAnalysis.Analyzer}.
 */
public class ResolutionInfo {

    private final ResolutionInfoInternal mResolutionInfoInternal;

    /**
     * Creates a new instance of {@link ResolutionInfo} with the given parameters. This
     * constructor is not normally needed outside of testing cases.
     *
     * @param resolution The resolution used for the {@link UseCase} expressed in the coordinates
     *                  of the camera sensor.
     * @param cropRect The crop rectangle specifies the region of valid pixels in the buffer.
     * @param rotationDegrees The clockwise rotation in degrees that needs to be applied to the
     *                       output buffer so the image appears upright at the target rotation
     *                        setting.
     *
     * @see #getResolution()
     * @see #getCropRect()
     * @see #getRotationDegrees()
     */
    public ResolutionInfo(@NonNull Size resolution, @NonNull Rect cropRect,
            @ImageOutputConfig.RotationDegreesValue int rotationDegrees) {
        mResolutionInfoInternal =
                new AutoValue_ResolutionInfo_ResolutionInfoInternal.Builder()
                        .setResolution(resolution)
                        .setCropRect(cropRect)
                        .setRotationDegrees(rotationDegrees)
                        .build();
    }

    /**
     * Returns the output resolution used for the use case.
     *
     * <p>The resolution will be expressed in the coordinates of the camera sensor. The
     * dimensions need to be flipped by the rotation degrees obtained via
     * {@link #getRotationDegrees()} to match the target rotation setting.
     */
    @NonNull
    public Size getResolution() {
        return mResolutionInfoInternal.getResolution();
    }

    /**
     * Returns the crop rectangle.
     *
     * <p>The crop rectangle specifies the region of valid pixels in the buffer, using
     * coordinates from <code>(0, 0)</code> to the <code>(width, height)</code> of the resolution
     * obtained by {@link #getResolution}. The dimensions need to be flipped by the rotation
     * degrees obtained via {@link #getRotationDegrees()} to match the target rotation setting.
     *
     * <p>If the use case is configured with a {@link ViewPort}, this value is calculated based
     * on the configuration of {@link ViewPort}; if not, it returns the full rect of the buffer
     * which the dimensions will be the same as the value obtained from {@link #getResolution}.
     */
    @NonNull
    public Rect getCropRect() {
        return mResolutionInfoInternal.getCropRect();
    }

    /**
     * Returns the rotation degrees needed to transform the output resolution to the target
     * rotation.
     *
     * <p>This is a clockwise rotation in degrees that needs to be applied to the output buffer
     * so the image appears upright at the target rotation setting. The rotation will be
     * determined by the camera sensor orientation value and target rotation setting.
     *
     * @return The rotation in degrees which will be a value in {0, 90, 180, 270}.
     */
    @ImageOutputConfig.RotationDegreesValue
    public int getRotationDegrees() {
        return mResolutionInfoInternal.getRotationDegrees();
    }

    @Override
    public int hashCode() {
        return mResolutionInfoInternal.hashCode();
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        return mResolutionInfoInternal.equals(obj);
    }

    @NonNull
    @Override
    public String toString() {
        return mResolutionInfoInternal.toString();
    }

    @AutoValue
    abstract static class ResolutionInfoInternal {
        @NonNull
        abstract Size getResolution();

        @NonNull
        abstract Rect getCropRect();

        @ImageOutputConfig.RotationDegreesValue
        abstract int getRotationDegrees();

        @AutoValue.Builder
        abstract static class Builder {
            @NonNull
            abstract Builder setResolution(@NonNull Size resolution);

            @NonNull
            abstract Builder setCropRect(@NonNull Rect cropRect);

            @NonNull
            abstract Builder setRotationDegrees(
                    @ImageOutputConfig.RotationDegreesValue int rotationDegrees);

            @NonNull
            abstract ResolutionInfoInternal build();
        }
    }
}