public interface

ImageReaderProxy

 androidx.camera.core.impl.ImageReaderProxy

Subclasses:

MetadataImageReader, SafeCloseImageReaderProxy

Gradle dependencies

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

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

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

Overview

An image reader proxy which has an analogous interface as .

Whereas an provides instances, an ImageReaderProxy provides ImageProxy instances.

Summary

Methods
public ImageProxyacquireLatestImage()

Acquires the latest image in the queue.

public ImageProxyacquireNextImage()

Acquires the next image in the queue.

public voidclearOnImageAvailableListener()

Clears the currently set ImageReaderProxy.OnImageAvailableListener.

public voidclose()

Closes the reader.

public intgetHeight()

Returns the image height.

public intgetImageFormat()

Returns the image format.

public intgetMaxImages()

Returns the max number of images in the queue.

public SurfacegetSurface()

Returns the underlying surface.

public intgetWidth()

Returns the image width.

public voidsetOnImageAvailableListener(ImageReaderProxy.OnImageAvailableListener listener, java.util.concurrent.Executor executor)

Sets the on-image-available listener.

Methods

public ImageProxy acquireLatestImage()

Acquires the latest image in the queue.

@see .

public ImageProxy acquireNextImage()

Acquires the next image in the queue.

@see .

public void close()

Closes the reader.

@see .

public int getHeight()

Returns the image height.

@see .

public int getWidth()

Returns the image width.

@see .

public int getImageFormat()

Returns the image format.

@see .

public int getMaxImages()

Returns the max number of images in the queue.

@see .

public Surface getSurface()

Returns the underlying surface.

@see .

public void setOnImageAvailableListener(ImageReaderProxy.OnImageAvailableListener listener, java.util.concurrent.Executor executor)

Sets the on-image-available listener.

Parameters:

listener: The listener that will be run.
executor: The executor on which the listener should be invoked.

public void clearOnImageAvailableListener()

Clears the currently set ImageReaderProxy.OnImageAvailableListener.

This does not cancel any currently in progress listener.

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 android.media.ImageReader;
import android.view.Surface;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.Scope;
import androidx.camera.core.ImageProxy;

import java.util.concurrent.Executor;

/**
 * An image reader proxy which has an analogous interface as {@link ImageReader}.
 *
 * <p>Whereas an {@link ImageReader} provides {@link android.media.Image} instances, an {@link
 * ImageReaderProxy} provides {@link ImageProxy} instances.
 *
 */

@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
public interface ImageReaderProxy {
    /**
     * Acquires the latest image in the queue.
     *
     * <p>@see {@link ImageReader#acquireLatestImage()}.
     */
    @Nullable
    ImageProxy acquireLatestImage();

    /**
     * Acquires the next image in the queue.
     *
     * <p>@see {@link ImageReader#acquireNextImage()}.
     */
    @Nullable
    ImageProxy acquireNextImage();

    /**
     * Closes the reader.
     *
     * <p>@see {@link ImageReader#close()}.
     */
    void close();

    /**
     * Returns the image height.
     *
     * <p>@see {@link ImageReader#getHeight()}.
     */
    int getHeight();

    /**
     * Returns the image width.
     *
     * <p>@see {@link ImageReader#getWidth()}.
     */
    int getWidth();

    /**
     * Returns the image format.
     *
     * <p>@see {@link ImageReader#getImageFormat()}.
     */
    int getImageFormat();

    /**
     * Returns the max number of images in the queue.
     *
     * <p>@see {@link ImageReader#getMaxImages()}.
     */
    int getMaxImages();

    /**
     * Returns the underlying surface.
     *
     * <p>@see {@link ImageReader#getSurface()}.
     */
    @Nullable
    Surface getSurface();

    /**
     * Sets the on-image-available listener.
     *
     * @param listener The listener that will be run.
     * @param executor The executor on which the listener should be invoked.
     */
    void setOnImageAvailableListener(
            @NonNull ImageReaderProxy.OnImageAvailableListener listener,
            @NonNull Executor executor);

    /**
     * Clears the currently set {@link OnImageAvailableListener}.
     *
     * <p> This does not cancel any currently in progress listener.
     */
    void clearOnImageAvailableListener();

    /**
     * A listener for newly available images.
     *
     * @hide
     */
    @RestrictTo(Scope.LIBRARY_GROUP)
    interface OnImageAvailableListener {
        /**
         * Callback for a newly available image.
         *
         * <p>@see {@link ImageReader.OnImageAvailableListener#onImageAvailable(ImageReader)}.
         */
        void onImageAvailable(@NonNull ImageReaderProxy imageReader);
    }
}