[Java] 纯文本查看 复制代码
public static String imgToBase64( Bitmap bitmap,int quality) {
if(bitmap == null){
//bitmap not found!!
}
ByteArrayOutputStream out = null;
try {
out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, out);
out.flush();
out.close();
byte[] imgBytes = out.toByteArray();
return Base64.encodeToString(imgBytes, Base64.NO_WRAP);
} catch (Exception e) {
// TODO Auto-generated catch block
return null;
} finally {
try {
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}