2017-07-17 130 views
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; 
} 

+0

任何机构得到的答案....? – Sayandh

+1

请参阅此链接[https://stackoverflow.com/questions/9224056/android-bitmap-to-base64-string] – Lucky

+0

是的,先生我也试过这个...但结果是一样的。 。转换正在进行,但我认为它格式不正确。 – Sayandh

回答

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); 
} 
+0

其相同的代码是吗? – Sayandh

+0

正在尝试它... – Sayandh

+0

是!但你没有发布你如何解码它。并确保你的位图不是空的。 – Shruti