为什么我的BitmapFactory.de codeByteArray的返回null? [英] Why is my BitmapFactory.decodeByteArray returning null?

查看:141
本文介绍了为什么我的BitmapFactory.de codeByteArray的返回null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存储在数据库中的Base64格式的图像,转换为位图,以在ImageView的使用。

I am trying to convert an image stored in Database in Base64 format, to a Bitmap to be used in an Imageview.

所以,我这种方式存储在SQLite的:

So, I store it in SQLite this way:

Bitmap imageBitmap = (Bitmap) extras.get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap fotoGrande=(Bitmap) extras.get("data");
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
//I am adding some data to EXIF here, add to an static ArrayList<Bitmap> in other class and I store it this way:

int bytes=listaFotos.get(i).getFoto().getByteCount();
ByteBuffer buffer = ByteBuffer.allocate(bytes);
listaFotos.get(i).getFoto().copyPixelsToBuffer(buffer);
values.put("foto", Base64.encodeToString(buffer.array(), Base64.DEFAULT));

后来,我需要得到的图像以适应其在ImageView的:

Later, i need to get that image to fit it in an ImageView:

String foto = csr2.getString(0);//csr2 is a cursor
byte[] arrayFoto = Base64.decode(foto, Base64.DEFAULT);//This is not null
Bitmap fotoBitmap = BitmapFactory.decodeByteArray(arrayFoto, 0, arrayFoto.length);//This is null

我知道有吨这个问题。我搜索,但没有回答解决我的问题。

I know there are tons of questions about this. I searched, but no answer fix my problem.

为什么我的BitmapFactory.de codeByteArray的返回null?我做错了什么?任何帮助吗?

Why is my BitmapFactory.decodeByteArray returning null? What I am doing wrong? Any help?

感谢您。

推荐答案

原来是一个数据库的问题。 SQLite的为您提供了1MB MAX大小的光标。我正在从数据库中的字节,1MB的光标时,PIC未发送正常。

Turned out to be a database issue. SQLite gives you a cursor of 1MB MAX size. I was getting the bytes from database, with a 1MB cursor, the pic was not sent properly.

要解决这个问题,我存放的路径,在数据库,而不是字节的照片。

To fix it, I stored the path to the photo in database instead of the bytes.

这篇关于为什么我的BitmapFactory.de codeByteArray的返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆