Android: using Base64 to encode an Image to String

北慕城南 提交于 2020-01-06 08:21:36

问题


I downloaded the Base64.java from here:

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/util/Base64.java

which contains method encodeToString() but its very low sized compared to what i had previously. Its just some 750 lines of code.

the previous 1 was downloaded from here:

http://sourceforge.net/projects/iharder/files/

which has 2064 lines of code but doesn't have the method encodeToString() instead it has only encodeToFile() method.

Which of these is more robust?

My purpose of using Base64 is to convert a ByteArray i get from Camera Api and send it to a Server(the encoded string).

Thank you


回答1:


Well, if you want to send the encoded image to your server, you should encode it into a String:

byte[] imageBytes = yourByteArray;
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);


来源:https://stackoverflow.com/questions/13026443/android-using-base64-to-encode-an-image-to-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!