繁体   English   中英

ByteArray到Bitmap给出null

[英]ByteArray to Bitmap gives null

我正在尝试将字节数组转换为位图以在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空,为什么?

试试这个链接。 它将解决您的问题

如何将字节数组转换为位图

或只是检查此代码

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

//如果bitmapdata是字节数组,则获取位图的过程如下

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM