这是我的代码,我已经尝试了很多代码变种......
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;
}
答案 0 :(得分:0)
您可以尝试使用以下代码对图像进行编码和解码:
//Compress img and save
private String encodeBitmapAndSave(Bitmap bitmap1) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap1.compress(Bitmap.CompressFormat.PNG, 100, baos);
return Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
}
//Decompress img
private Bitmap decodeFromFirebaseBase64(String image) throws IOException {
byte[] decodedByteArray = Base64.decode(image, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(decodedByteArray, 0, decodedByteArray.length);
}