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