當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageFormat.YUV_420_888屬性代碼示例

本文整理匯總了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);
}
 
開發者ID:BioID-GmbH,項目名稱:BWS-Android,代碼行數:22,代碼來源:IntensityPlane.java

示例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();
            }
        }
    }
}
 
開發者ID:yohhoy,項目名稱:heifreader,代碼行數:27,代碼來源:HeifReader.java

示例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();
}
 
開發者ID:lydia-schiff,項目名稱:hella-renderscript,代碼行數:12,代碼來源:RsUtil.java

示例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;
}
 
開發者ID:InnoFang,項目名稱:FamilyBond,代碼行數:15,代碼來源:ImageUtil.java


注:本文中的android.graphics.ImageFormat.YUV_420_888屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。