-
public class BitmapUtilsUtils functions for bitmap conversions.
-
-
Method Summary
Modifier and Type Method Description static BitmapgetBitmap(Array<byte> nv21Data, FrameMetadata frameMetadata)Converts NV21 format byte to bitmap. static BitmapgetBitmap(ByteBuffer data, int width, int height, int rotationDegrees)Converts NV21 format byte buffer to bitmap. static BitmapgetBitmap(ImageProxy image)Converts a YUV_420_888 image from CameraX API to a bitmap. static BitmapgetBitmapFromContentUri(ContentResolver contentResolver, Uri imageUri)static Array<byte>yuv420ThreePlanesToNV21(Array<Image.Plane> yuv420888planes, int width, int height)Converts YUV_420_888 to NV21 bytes. -
-
Method Detail
-
getBitmap
@Nullable() static Bitmap getBitmap(Array<byte> nv21Data, FrameMetadata frameMetadata)
Converts NV21 format byte to bitmap.
-
getBitmap
@Nullable() static Bitmap getBitmap(ByteBuffer data, int width, int height, int rotationDegrees)
Converts NV21 format byte buffer to bitmap.
-
getBitmap
@Nullable() static Bitmap getBitmap(ImageProxy image)
Converts a YUV_420_888 image from CameraX API to a bitmap.
-
getBitmapFromContentUri
@RequiresApi(api = Build.VERSION_CODES.N)@Nullable() static Bitmap getBitmapFromContentUri(ContentResolver contentResolver, Uri imageUri)
-
yuv420ThreePlanesToNV21
static Array<byte> yuv420ThreePlanesToNV21(Array<Image.Plane> yuv420888planes, int width, int height)
Converts YUV_420_888 to NV21 bytes.
The NV21 format consists of a single byte array containing the Y, U and V values. For animage of size S, the first S positions of the array contain all the Y values. The remainingpositions contain interleaved V and U values. U and V are subsampled by a factor of 2 in bothdimensions, so there are S/4 U values and S/4 V values. In summary, the NV21 array will containS Y values followed by S/4 VU values: YYYYYYYYYYYYYY(...)YVUVUVUVU(...)VU
YUV_420_888 is a generic format that can describe any YUV image where U and V are subsampledby a factor of 2 in both dimensions. getPlanes returns an array with the Y, U andV planes. The Y plane is guaranteed not to be interleaved, so we can just copy its values intothe first part of the NV21 array. The U and V planes may already have the representation in theNV21 format. This happens if the planes share the same buffer, the V buffer is one positionbefore the U buffer and the planes have a pixelStride of 2. If this is case, we can just copythem to the NV21 array.
-
-
-
-