JAVA图片转base64

//Author  : JACK
//File    : App.java
//Time    : 2020/7/27 15:51
package image_base64;
import java.net.URLEncoder;
import com.baidu.ai.aip.Base64Util;
import com.baidu.ai.aip.FileUtil;
import com.baidu.ai.aip.HttpUtil;


public class App 
{
    public static void main(String[] args) throws Exception
    {
        /**
         * 重要提示代码中所需工具类
         * FileUtil,Base64Util,HttpUtil,GsonUtils请从
         * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
         * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
         * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
         * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
         * 下载
         */
        // iocr识别apiUrl
        String recogniseUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise/finance";
        String filePath = "...\\image.jpg";
        try {
                byte[] imgData = FileUtil.readFileByBytes(filePath);
                String imgStr = Base64Util.encode(imgData);               
                System.out.println("图片转换成功的base6:"+imgStr);
        } catch (Exception e) {
                e.printStackTrace();
        }
    }
}

  

posted @ 2021-02-07 14:48  mahaining  阅读(113)  评论(0编辑  收藏  举报