ImageProxy

@RequiresApi(value = 21)
interface ImageProxy : AutoCloseable


An image proxy which has a similar interface as android.media.Image.

Summary

Nested types

A plane proxy which has an analogous interface as android.media.Image.Plane.

Public functions

Unit

Closes the underlying android.media.Image.

Rect

Returns the crop rectangle.

Int

Returns the image format.

Int

Returns the image height.

Image?

Returns the android Image.

ImageInfo

Returns the ImageInfo.

Array<ImageProxy.PlaneProxy!>

Returns the array of planes.

Int

Returns the image width.

Unit
setCropRect(rect: Rect?)

Sets the crop rectangle.

Bitmap

Converts ImageProxy to Bitmap.

Public functions

close

Added in 1.0.0
fun close(): Unit

Closes the underlying android.media.Image.

See also
close

getCropRect

Added in 1.0.0
fun getCropRect(): Rect

Returns the crop rectangle.

See also
getCropRect

getFormat

Added in 1.0.0
fun getFormat(): Int

Returns the image format.

The image format can be one of the ImageFormat or PixelFormat constants.

See also
getFormat

getHeight

Added in 1.0.0
fun getHeight(): Int

Returns the image height.

See also
getHeight

getImage

Added in 1.0.0
@ExperimentalGetImage
fun getImage(): Image?

Returns the android Image.

If the ImageProxy is a wrapper for an android Image, it will return the Image. It is possible for an ImageProxy to wrap something that isn't an Image. If that's the case then it will return null.

The returned image should not be closed by the application. Instead it should be closed by the ImageProxy, which happens, for example, on return from the ImageAnalysis.Analyzer function. Destroying the ImageAnalysis will close the underlying android.media.ImageReader. So an Image obtained with this method will behave as such.

Returns
Image?

the android image.

See also
close

getImageInfo

Added in 1.0.0
fun getImageInfo(): ImageInfo

Returns the ImageInfo.

getPlanes

Added in 1.0.0
fun getPlanes(): Array<ImageProxy.PlaneProxy!>

Returns the array of planes.

See also
getPlanes

getWidth

Added in 1.0.0
fun getWidth(): Int

Returns the image width.

See also
getWidth

setCropRect

Added in 1.0.0
fun setCropRect(rect: Rect?): Unit

Sets the crop rectangle.

See also
setCropRect

toBitmap

Added in 1.3.0
fun toBitmap(): Bitmap

Converts ImageProxy to Bitmap.

The supported ImageProxy format is YUV_420_888, JPEG or RGBA_8888. If format is invalid, an IllegalArgumentException will be thrown. If the conversion to bimap failed, an UnsupportedOperationException will be thrown.

Returns
Bitmap

Bitmap instance.