图片跟base64字节互转
public static String getFileBase64(String url) { try { File file = new File(url); FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; inputFile.read(buffer); inputFile.close(); return Base64.encodeToString(buffer, Base64.DEFAULT); } catch (Exception e) { e.printStackTrace(); } return ""; } public Bitmap getBitmapForBase64Str(String base64Str) { if (base64Str.contains(",")){ base64Str = base64Str.split(",")[1]; } byte[] decode = Base64.decode(base64Str, Base64.DEFAULT); return BitmapFactory.decodeByteArray(decode, 0, decode.length); }
最简单的教养,就是适当地回避别人的难堪。