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;
}
posted @ 2016-10-19 10:22  黑色秋梨膏  阅读(1645)  评论(0编辑  收藏  举报