【问题标题】:How can I create a YuvImage in android如何在 android 中创建 YuvImage
【发布时间】:2014-04-06 07:17:01
【问题描述】:

出于测试目的,我需要创建一个 NV21 格式的 yuv 图像。

从这个帖子Displaying YUV Image in Android,我看到它确实:

YuvImage yuvImage = new YuvImage(data, PictureFormat.NV21, width, 高度,空);

如何获取“数据”?传递 yuvImage? 我可以从资源文件中加载它吗,资源文件格式应该是什么?

【问题讨论】:

    标签: android image


    【解决方案1】:

    您可以通过将资源 Drawable 转换为 Bytearray 来获取所需的参数(数据),然后使用它来获取 YUV 图像:

    Resources res = getResources();
    Drawable drawable = res.getDrawable(R.drawable.my_pic);
    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] bitMapData = stream.toByteArray();
    

    【讨论】:

    • 'my_pic' 是 jpg 吗?或者它是什么样的文件?为什么我需要调用“bitmap.compress()”?
    • my_pic 是可绘制的图像,Jpg 或 Png .. 您需要参考 android.graphics.Bitmap 才能使用“压缩”方法..
    猜你喜欢
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-20
    相关资源
    最近更新 更多