本文整理汇总了Java中android.graphics.ImageFormat.YUV_420_888属性的典型用法代码示例。如果您正苦于以下问题:Java ImageFormat.YUV_420_888属性的具体用法?Java ImageFormat.YUV_420_888怎么用?Java ImageFormat.YUV_420_888使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.graphics.ImageFormat
的用法示例。
在下文中一共展示了ImageFormat.YUV_420_888属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extract
/**
* Extracts the Y-Plane from the YUV_420_8888 image to creates a IntensityPlane.
* The actual plane data will be copied into the new IntensityPlane object.
*
* @throws IllegalArgumentException if the provided images is not in the YUV_420_888 format
*/
@NonNull
public static IntensityPlane extract(@NonNull Image img) {
if (img.getFormat() != ImageFormat.YUV_420_888) {
throw new IllegalArgumentException("image format must be YUV_420_888");
}
Image.Plane[] planes = img.getPlanes();
ByteBuffer buffer = planes[0].getBuffer();
byte[] yPlane = new byte[buffer.remaining()];
buffer.get(yPlane);
int yRowStride = planes[0].getRowStride();
return new IntensityPlane(img.getWidth(), img.getHeight(), yPlane, yRowStride);
}
示例2: renderHevcImageWithFormat
private static Bitmap renderHevcImageWithFormat(ByteBuffer bitstream, ImageInfo info, int imageFormat) throws FormatFallbackException {
try (ImageReader reader = ImageReader.newInstance(info.size.getWidth(), info.size.getHeight(), imageFormat, 1)) {
renderHevcImage(bitstream, info, reader.getSurface());
Image image = null;
try {
try {
image = reader.acquireNextImage();
} catch (UnsupportedOperationException ex) {
throw new FormatFallbackException(ex);
}
switch (image.getFormat()) {
case ImageFormat.YUV_420_888:
case ImageFormat.YV12:
return convertYuv420ToBitmap(image);
case ImageFormat.RGB_565:
return convertRgb565ToBitmap(image);
default:
throw new RuntimeException("unsupported image format(" + image.getFormat() + ")");
}
} finally {
if (image != null) {
image.close();
}
}
}
}
示例3: createYuvType
@RequiresApi(18)
public static Type createYuvType(RenderScript rs, int x, int y, int yuvFormat) {
boolean supported = yuvFormat == ImageFormat.NV21 || yuvFormat == ImageFormat.YV12;
if (Build.VERSION.SDK_INT >= 19) {
supported |= yuvFormat == ImageFormat.YUV_420_888;
}
if (!supported) {
throw new IllegalArgumentException("invalid yuv format: " + yuvFormat);
}
return new Type.Builder(rs, createYuvElement(rs)).setX(x).setY(y).setYuvFormat(yuvFormat)
.create();
}
示例4: imageToByteArray
public static byte[] imageToByteArray(Image image) {
byte[] data = null;
if (image.getFormat() == ImageFormat.JPEG) {
Image.Plane[] planes = image.getPlanes();
ByteBuffer buffer = planes[0].getBuffer();
data = new byte[buffer.capacity()];
buffer.get(data);
return data;
} else if (image.getFormat() == ImageFormat.YUV_420_888) {
data = NV21toJPEG(
YUV_420_888toNV21(image),
image.getWidth(), image.getHeight());
}
return data;
}