public final class

SingleImageProxyBundle

extends java.lang.Object

implements ImageProxyBundle

 java.lang.Object

↳androidx.camera.core.impl.SingleImageProxyBundle

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

An ImageProxyBundle that contains a single ImageProxy.

Summary

Constructors
publicSingleImageProxyBundle(ImageProxy imageProxy, java.lang.String tagBundleKey)

Create an ImageProxyBundle from a single ImageProxy using a tag's value from the ImageProxy as the captureId.

Methods
public voidclose()

Close the ImageProxy that has been wrapped by the bundle.

public java.util.List<java.lang.Integer>getCaptureIds()

public <any>getImageProxy(int captureId)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public SingleImageProxyBundle(ImageProxy imageProxy, java.lang.String tagBundleKey)

Create an ImageProxyBundle from a single ImageProxy using a tag's value from the ImageProxy as the captureId. The tagBundleKey is used to query from a TagBundle. It needs to be one of the keys that are in the ImageInfo's TagBundle.

Methods

public void close()

Close the ImageProxy that has been wrapped by the bundle.

public <any> getImageProxy(int captureId)

public java.util.List<java.lang.Integer> getCaptureIds()

Source

/*
 * Copyright 2019 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.impl;

import androidx.annotation.NonNull;
import androidx.camera.core.ImageInfo;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.impl.utils.futures.Futures;

import com.google.common.util.concurrent.ListenableFuture;

import java.util.Collections;
import java.util.List;

/**
 * An {@link ImageProxyBundle} that contains a single {@link ImageProxy}.
 */
public final class SingleImageProxyBundle implements ImageProxyBundle {
    private final int mCaptureId;
    private final ImageProxy mImageProxy;

    /**
     * Create an {@link ImageProxyBundle} from a single {@link ImageProxy} using a tag's value from
     * the ImageProxy as the captureId.
     *
     * The tagBundleKey is used to query from a TagBundle. It needs to be one of the keys that are
     * in the ImageInfo's TagBundle.
     *
     * @throws IllegalArgumentException if the ImageProxy doesn't contain a tag
     */
    public SingleImageProxyBundle(@NonNull ImageProxy imageProxy,
            @NonNull String tagBundleKey) {
        ImageInfo imageInfo = imageProxy.getImageInfo();

        if (imageInfo == null) {
            throw new IllegalArgumentException("ImageProxy has no associated ImageInfo");
        }

        Integer tagValue = (Integer) imageInfo.getTagBundle().getTag(tagBundleKey);

        if (tagValue == null) {
            throw new IllegalArgumentException("ImageProxy has no associated tag");
        }

        mCaptureId = tagValue;
        mImageProxy = imageProxy;
    }

    /**
     * Create an {@link ImageProxyBundle} from a single {@link ImageProxy} using a specified
     * captureId.
     */
    SingleImageProxyBundle(@NonNull ImageProxy imageProxy, int captureId) {
        mCaptureId = captureId;
        mImageProxy = imageProxy;
    }

    /** Close the {@link ImageProxy} that has been wrapped by the bundle. */
    public void close() {
        mImageProxy.close();
    }

    @Override
    @NonNull
    public ListenableFuture<ImageProxy> getImageProxy(int captureId) {
        if (captureId != mCaptureId) {
            return Futures.immediateFailedFuture(
                    new IllegalArgumentException("Capture id does not exist in the bundle"));
        }
        return Futures.immediateFuture(mImageProxy);
    }

    @Override
    @NonNull
    public List<Integer> getCaptureIds() {
        return Collections.singletonList(mCaptureId);
    }
}