【问题标题】:How to convert a byte array to an image which can be displayed on an Android screen?如何将字节数组转换为可以在 Android 屏幕上显示的图像?
【发布时间】:2018-03-09 17:29:49
【问题描述】:

我有字节数组形式的原始单色数据(每个像素一个字节)。

获取此数据并将其作为图像显示在屏幕上的最低延迟方法是什么?

(它需要足够快才能将 720x480 帧显示为 30fps 视频。)

这不是 conversion of byte array to image 的副本,也不能使用 decodeByteArray 解决,因为此字节数组包含原始数据,而不是 decodeByteArray 要求的“压缩图像数据的字节数组”。

【问题讨论】:

标签: android arrays video-streaming


【解决方案1】:

可能有方法涉及BitMap.createBitmap

createBitmap
added in API level 1

Bitmap createBitmap (int[] colors, 
                int width, 
                int height, 
                Bitmap.Config config)

Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array. Its initial density is as per getDensity(). The newly created bitmap is in the sRGB color space.

https://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap(int[],%20int,%20int,%20android.graphics.Bitmap.Config)

【讨论】:

    【解决方案2】:
    Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    ImageView image = (ImageView) findViewById(R.id.imageView1);
    
    image.setImageBitmap(Bitmap.createScaledBitmap(bmp, image.getWidth(),
                    image.getHeight(), false)));
    
    here you can set image on imageview after converting byte array to bitmap and then scaling that bitmap and setting on imageview
    

    【讨论】:

    • 字节数组包含原始单色数据,而不是decodeByteArray 要求的“压缩图像数据的字节数组”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    • 2016-11-02
    • 2011-11-25
    相关资源
    最近更新 更多