【发布时间】:2015-07-21 12:04:26
【问题描述】:
我正在尝试将存储在数据库中的 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?我做错了什么?有什么帮助吗?
谢谢。
【问题讨论】:
-
如果图像无法解码,则返回 null。
-
是的,我知道,我读了文档,我想知道为什么图像无法解码。
-
可能是因为这样做的内存用完了。拍摄一个非常小的图像,您会看到它已解码。