- public static String GetImageStr(File img) {
- byte[] data = null;
- // 读取图片字节数组
- try {
- InputStream in = new FileInputStream(img);
- data = new byte[in.available()];
- in.read(data);
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- // 对字节数组Base64编码
- BASE64Encoder encoder = new BASE64Encoder();
- return encoder.encode(data);// 返回Base64编码过的字节数组字符串
- }
- //该片段来自于http://www.codesnippet.cn/detail/191120137264.html
来源: http://www.codesnippet.cn/detail/191120137264.html