【问题标题】:ByteArray to Bitmap gives nullByteArray 到 Bitmap 给出 null
【发布时间】:2013-10-18 04:56:12
【问题描述】:

我正在尝试将字节数组转换为位图以在 android 应用程序中显示图像。但是在转换它时返回空值。我使用了以下代码:

operations = new DataBaseOperations();
byte image[] = operations.fetchimage(); // gets byte array from the database        
BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeByteArray(image, 0, image.length, options);

这里bitmap 为空,为什么?

【问题讨论】:

标签: android bitmap


【解决方案1】:

试试这个链接。它会解决你的问题

How to convert byte array to Bitmap

或者只是检查这个代码

Bitmap bitmap = BitmapFactory.decodeFile("/path/images.jpg");
ByteArrayOutputStream blob = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, blob);
byte[] bitmapdata = blob.toByteArray();

//如果位图数据是字节数组,那么获取位图是这样的

Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata .length);

返回解码后的位图,如果图像无法解码,则返回 null。

【讨论】:

  • 我要为空。如何以任何其他方式对其进行解码?如果图像无法解码。有可能吗??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-09
相关资源
最近更新 更多