public static String encodeBase64File(String path) throws IOException { String type = path.substring(path.lastIndexOf(".") + 1); if (type.equals("jpg") || type.equals("png")) { Bitmap bm = getSmallBitmap(path); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (null == bm) { return null; } bm.compress(Bitmap.CompressFormat.JPEG, 80, baos); byte[] b = baos.toByteArray(); return Base64.encodeToString(b, Base64.DEFAULT); } else { File file = new File(path); FileInputStream inputFile = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; inputFile.read(buffer); inputFile.close(); return Base64.encodeToString(buffer, Base64.DEFAULT); } }
根据图片文件路径,把图片转化为base64
最新推荐文章于 2024-05-20 22:28:51 发布