Base64編碼文件爲字符串
public static String encodeBase64File(File file) throws Exception {
FileInputStream inputFile = new FileInputStream(file);
byte[] buffer = new byte[(int) file.length()];
inputFile.read(buffer);
inputFile.close();
return Base64.encodeToString(buffer, Base64.DEFAULT);
}
Base64編碼Bitmap爲字符串
public String bitmapToString(Bitmap bitmap) {
ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);
byte[] bytes = bitmapStream.toByteArray();
return Base64.encodeToString(bytes, Base64.DEFAULT);
}