0
我以下列方式编码的图像,并将其存储在我的数据库:位图 - Base64编码字符串 - 位图转换的Android
public String getStringImage(Bitmap bmp){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
return encodedImage;
}
现在,我想它以下列方式进行解码,并在显示它ImageView
:
try{
InputStream stream = new ByteArrayInputStream(image.getBytes());
Bitmap bitmap = BitmapFactory.decodeStream(stream);
return bitmap;
}
catch (Exception e) {
return null;
}
}
然而ImageView
保持空白,并且不显示图像。我错过了什么吗?
你是说我应该这样做,而不是我的try/catch块或补充呢? – Alk
它工作时,我只是用你提供的代码替换try catch) – Alk