OutOfMemoryError while decoding and encoding Base64 String into Bitmap

前端 未结 7 1998
你的背包
你的背包 2020-12-14 14:49

I\'m trying to decode and encode a Bitmap image. On some devices it runs perfectly while on others it\'s not. I\'m uploading Bas

7条回答
  •  执念已碎
    2020-12-14 15:13

    You are not base64 encoding a Bitmap instance (as you suggest in your post and even in the subject) but a byte array b in String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);. The byte array 'b' contains the bytes of what would be the content of a .jpg file if you would write these bytes to file.

    What you have to do is put the contents of the .jpg file which you want to upload directly in a byte array. Then encode that array.

    Google for android put file content in byte array. Code has been posted many times on this site

提交回复
热议问题