CZT
2023-09-06 71c4fa1e27f75ae4b765c95c67a3069c84dc72ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.ld.igds.sh.util;
 
import com.ld.igds.constant.DepotStatus;
import org.springframework.stereotype.Component;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
 
/**
 * 接口转换工具类
 *
 * @author chen
 **/
@Component
public class ApiShUtil {
 
 
    /**
     * 获取图片的二进制流
     *
     * @param imgPath
     * @return
     */
    public String imgToIo(String imgPath) {
        //图片转化为二进制
        byte[] imageBytes = null;
        try {
 
            FileInputStream fileInputStream = new FileInputStream(new File(imgPath));
            imageBytes = new byte[fileInputStream.available()];
            fileInputStream.read(imageBytes);
        } catch (IOException e) {
 
            System.out.println(e);
            return null;
        }
        return UnicodeByteToStr(imageBytes);
    }
 
    private static String UnicodeByteToStr(byte[] b) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < b.length; i++) {
            sb.append(String.format("%02x", b[i]));
        }
        return sb.toString();
    }
}