提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.workflow.core.util; |
懒 |
2 |
|
|
3 |
import org.apache.commons.codec.binary.Base64; |
|
4 |
|
|
5 |
import java.io.FileInputStream; |
|
6 |
import java.io.IOException; |
|
7 |
import java.io.InputStream; |
|
8 |
|
|
9 |
/** |
|
10 |
* BASE64处理 |
|
11 |
* |
|
12 |
* @author fengshuonan |
|
13 |
* @Date 2019-08-27 18:33 |
|
14 |
*/ |
|
15 |
public class ImageAnd64Binary { |
|
16 |
|
|
17 |
/** |
|
18 |
* 将图片文件转化为字节数组字符串,并对其进行Base64编码处理 |
|
19 |
* |
|
20 |
* @param imgSrcPath 生成64编码的图片的路径 |
|
21 |
* @return |
|
22 |
*/ |
|
23 |
public static String getImageStr(String imgSrcPath) { |
|
24 |
InputStream in = null; |
|
25 |
byte[] data = null; |
|
26 |
|
|
27 |
// 读取图片字节数组 |
|
28 |
try { |
|
29 |
in = new FileInputStream(imgSrcPath); |
|
30 |
data = new byte[in.available()]; |
|
31 |
in.read(data); |
|
32 |
in.close(); |
|
33 |
} catch (IOException e) { |
|
34 |
e.printStackTrace(); |
|
35 |
} |
|
36 |
|
|
37 |
// 返回Base64编码过的字节数组字符串 |
|
38 |
return Base64.encodeBase64String(data); |
|
39 |
} |
|
40 |
|
|
41 |
} |