將圖片轉換成Base64編碼
//參數imgFile:圖片完整路徑 public static String getImgBase64Str(String imgFile) { // 將圖片文件轉化為字節數組字符串,並對其進行Base64編碼處理 InputStream in = null; byte[] data = null; // 讀取圖片字節數組 try { in = new FileInputStream(imgFile); data = new byte[in.available()]; in.read(data); in.close(); } catch (IOException e) { e.printStackTrace(); } return Base64.encodeBase64String(data); }
