android - 为什么我的 BitmapFactory.decodeByteArray 返回 null?

标签 android android-bitmap

我正在尝试将以 Base64 格式存储在数据库中的图像转换为要在 Imageview 中使用的位图。

因此,我以这种方式将其存储在 SQLite 中:

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:

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

我知道有很多关于此的问题。我进行了搜索,但没有答案可以解决我的问题。

为什么我的 BitmapFactory.decodeByteArray 返回 null?我做错了什么?有帮助吗?

谢谢。

最佳答案

原来是数据库问题。 SQLite 给你一个 1MB MAX 大小的游标。我正在从数据库中获取字节,光标为 1MB,图片发送不正确。

为了修复它,我将照片的路径而不是字节存储在数据库中。

关于android - 为什么我的 BitmapFactory.decodeByteArray 返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31538548/

相关文章:

android - Action Bar 是不可或缺的吗?

android:合并文本和图像时更改了文本大小

android如何将pdf转换为图像并在imageview中加载

android - 有效地从 TextureView 获取位图

c# - 检查设备是否具有跨平台方式的摄像头

android - 用于 XML 文件的 Eclipse 拾色器插件

java - 制作一个创建对象并在单击时显示的按钮

android - 共享元素过渡到 RecyclerView 中的 View ,可能吗?

android - 位图未显示在 Canvas 上

Android:将图像对象转换为位图不起作用