Sdílet prostřednictvím


ImageReader.AcquireLatestImage Method

Definition

Acquire the latest Image from the ImageReader's queue, dropping older Image images.

[Android.Runtime.Register("acquireLatestImage", "()Landroid/media/Image;", "GetAcquireLatestImageHandler")]
public virtual Android.Media.Image? AcquireLatestImage ();
[<Android.Runtime.Register("acquireLatestImage", "()Landroid/media/Image;", "GetAcquireLatestImageHandler")>]
abstract member AcquireLatestImage : unit -> Android.Media.Image
override this.AcquireLatestImage : unit -> Android.Media.Image

Returns

latest frame of image data, or null if no image data is available.

Attributes

Exceptions

if too many images are currently acquired

Remarks

Acquire the latest Image from the ImageReader's queue, dropping older Image images. Returns null if no new image is available.

This operation will acquire all the images possible from the ImageReader, but #close all images that aren't the latest. This function is recommended to use over #acquireNextImage for most use-cases, as it's more suited for real-time processing.

Note that #getMaxImages maxImages should be at least 2 for #acquireLatestImage to be any different than #acquireNextImage - discarding all-but-the-newest Image requires temporarily acquiring two Image Images at once. Or more generally, calling #acquireLatestImage with less than two images of margin, that is (maxImages - currentAcquiredImages < 2) will not discard as expected.

This operation will fail by throwing an IllegalStateException if maxImages have been acquired with #acquireLatestImage or #acquireNextImage. In particular a sequence of #acquireLatestImage calls greater than #getMaxImages without calling Image#close in-between will exhaust the underlying queue. At such a time, IllegalStateException will be thrown until more images are released with Image#close.

Java documentation for android.media.ImageReader.acquireLatestImage().

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