如何将字节数组转换为可以在Android屏幕上显示的图像?

时间:2018-03-09 08:41:30

标签: android arrays video-streaming

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

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

(它需要足够快以显示720x480帧作为30fps视频。)

这不是conversion of byte array to image的重复,并且未使用decodeByteArray解决,因为此字节数组包含原始数据,而不是#34;压缩图像数据的字节数组" as decodeByteArray需要。

3 个答案:

答案 0 :(得分:0)

可能有一种涉及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)

答案 1 :(得分:-1)

使用BitmapFactory。请尝试下面的代码

Bitmap bitmap = BitmapFactory.decodeByteArray(img, 0, img.length); //image is you byte array.

使用以下方法进行压缩。

  ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
                byte[] bt = stream.toByteArray();

答案 2 :(得分:-1)

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