本文整理匯總了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;
}