目的地-Destination 前程似锦、未来可期、寻得良人、共赴白头,祝你也祝我。
博主 目的地-Destination
沪ICP备16003146号-2沪公网安备 31010702004922号萌ICP备20238488号博主 昨天 17:25 在线自豪地使用 Typecho 建站搭配使用 🌻Sunny 主题当前在线 22 人
歌曲封面 未知作品

沪ICP备16003146号-2

沪公网安备 31010702004922号

萌ICP备20238488号

网站已运行 7 年 342 天 1 小时 13 分

Powered by Typecho & Sunny

23 online · 51 ms

Title

Java将图片Base64编码转换成img图片文件

Chrison

·

烂笔头

·

Article
⚠️ 本文最后更新于2022年12月13日,已经过了679天没有更新,若内容或图片失效,请留言反馈

完整Demo

♾️ text 代码:
/**
 * 将图片Base64编码转换成img图片文件
 *
 * @param imgBase64 图片Base64编码
 * @param imgPath   图片生成路径
 * @return
 */
public static boolean getImgBase64ToImgFile(String imgBase64, String imgPath) {
    boolean flag = true;
    OutputStream outputStream = null;
    try {
        // 解密处理数据
        byte[] bytes = Base64.getDecoder().decode(imgBase64);
        for (int i = 0; i < bytes.length; ++i) {
            if (bytes[i] < 0) {
                bytes[i] += 256;
            }
        }
        outputStream = new FileOutputStream(imgPath);
        outputStream.write(bytes);
    } catch (Exception e) {
        e.printStackTrace();
        flag = false;
    } finally {
        if (outputStream != null) {
            try {
                // 关闭outputStream流
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return flag;
}

Java将网络链接图片或者本地图片文件转换成Base64编码字符串

请查看站内文章 ---> Java将网络链接图片或者本地图片文件转换成Base64编码字符串

现在已有 201 次阅读,0 条评论,0 人点赞
Comment:共0条
发表
搜 索 消 息 足 迹
你还不曾留言过..
你还不曾留下足迹..
博主 不再显示
博主