
正文
bitmap转化base64
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
/**
* bitmap转化base64
*/
public static String bitmapToBase64(Bitmap bitmap) { String result = null;
ByteArrayOutputStream baos = null;
try {
if (bitmap != null) {
baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); try {
baos.flush();
baos.close();
} catch (IOException e) {
e.printStackTrace();
} byte[] bitmapBytes = baos.toByteArray();
result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
}
} finally {
try {
if (baos != null) {
baos.flush();
baos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}






