YuvImage

open class YuvImage
kotlin.Any
   ↳ android.graphics.YuvImage

YuvImage contains YUV data and provides a method that compresses a region of the YUV data to a Jpeg. The YUV data should be provided as a single byte array irrespective of the number of image planes in it. Currently only ImageFormat.NV21 and ImageFormat.YUY2 are supported. To compress a rectangle region in the YUV data, users have to specify the region by left, top, width and height.
Requires API level 8 (Android 2.2, Froyo)

Summary

Public constructors
<init>(yuv: ByteArray!, format: Int, width: Int, height: Int, strides: IntArray!)

Construct an YuvImage.

Public methods
open Boolean
compressToJpeg(rectangle: Rect!, quality: Int, stream: OutputStream!)

Compress a rectangle region in the YuvImage to a jpeg.

open Int


Requires API level 8 (Android 2.2, Froyo)

open Int


Requires API level 8 (Android 2.2, Froyo)

open ByteArray!


Requires API level 8 (Android 2.2, Froyo)

open Int


Requires API level 8 (Android 2.2, Froyo)

open IntArray!


Requires API level 8 (Android 2.2, Froyo)

Public constructors

<init>

YuvImage(yuv: ByteArray!, format: Int, width: Int, height: Int, strides: IntArray!)

Construct an YuvImage.

Parameters
yuv ByteArray!: The YUV data. In the case of more than one image plane, all the planes must be concatenated into a single byte array.
format ByteArray!: The YUV data format as defined in ImageFormat.
width ByteArray!: The width of the YuvImage.
height ByteArray!: The height of the YuvImage.
strides ByteArray!: (Optional) Row bytes of each image plane. If yuv contains padding, the stride of each image must be provided. If strides is null, the method assumes no padding and derives the row bytes by format and width itself.
Exceptions
IllegalArgumentException if format is not support; width or height <= 0; or yuv is null.

Public methods

compressToJpeg

added in API level 8
open fun compressToJpeg(rectangle: Rect!, quality: Int, stream: OutputStream!): Boolean

Compress a rectangle region in the YuvImage to a jpeg. Only ImageFormat.NV21 and ImageFormat.YUY2 are supported for now.
Requires API level 8 (Android 2.2, Froyo)

Parameters
rectangle Rect!: The rectangle region to be compressed. The medthod checks if rectangle is inside the image. Also, the method modifies rectangle if the chroma pixels in it are not matched with the luma pixels in it.
quality Rect!: Hint to the compressor, 0-100. 0 meaning compress for small size, 100 meaning compress for max quality.
stream Rect!: OutputStream to write the compressed data.
Return
Boolean: True if the compression is successful.
Exceptions
IllegalArgumentException if rectangle is invalid; quality is not within [0, 100]; or stream is null.

getYuvFormat

added in API level 8
open fun getYuvFormat(): Int


Requires API level 8 (Android 2.2, Froyo)

Return
Int: the YUV format as defined in ImageFormat.

getHeight

added in API level 8
open fun getHeight(): Int


Requires API level 8 (Android 2.2, Froyo)

Return
Int: the height of the image.

getYuvData

added in API level 8
open fun getYuvData(): ByteArray!


Requires API level 8 (Android 2.2, Froyo)

Return
ByteArray!: the YUV data.

getWidth

added in API level 8
open fun getWidth(): Int


Requires API level 8 (Android 2.2, Froyo)

Return
Int: the width of the image.

getStrides

added in API level 8
open fun getStrides(): IntArray!


Requires API level 8 (Android 2.2, Froyo)

Return
IntArray!: the number of row bytes in each image plane.