Android 照片檔案轉化為而二進位制流
阿新 • • 發佈:2019-02-02
/** * 照片轉byte二進位制 * @param imagepath 需要轉byte的照片路徑 * @return 已經轉成的byte * @throws Exception */ public static byte[] readStream(String imagepath) throws Exception { FileInputStream fs = new FileInputStream(imagepath); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while (-1 != (len = fs.read(buffer))) { outStream.write(buffer, 0, len); } outStream.close(); fs.close(); return outStream.toByteArray(); }
params.add("img", String.valueOf(readStream(img)));