码迷,mamicode.com
首页 > 其他好文 > 详细

将图片转化为base64编码字符串

时间:2019-12-17 20:37:45      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:enc   pid   read   ges   nts   base   ack   encode   static   

pom依赖


        <dependency>
            <groupId>org.ops4j.base</groupId>
            <artifactId>ops4j-base-net</artifactId>
            <version>1.5.0</version>
        </dependency>

import org.ops4j.net.Base64Encoder;

        /**
     * 根据图片地址转换为base64编码字符串
     * @param imgFile 图片文件名称
     * @return
     * @author xuehp
     * @date 2019年6月4日 下午12:28:40
     */
    public static String getImageStr(String imgFile) {
        InputStream inputStream = null;
        byte[] data = null;
        try {
            inputStream = new FileInputStream(imgFile);
            data = new byte[inputStream.available()];
            inputStream.read(data);
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 加密
        return new String(Base64Encoder.encode(data));
    }

话说java是真麻烦啊~~

将图片转化为base64编码字符串

标签:enc   pid   read   ges   nts   base   ack   encode   static   

原文地址:https://www.cnblogs.com/xuehuiping/p/12056344.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!