您的位置 首页 java

Java之base64转化成图片文件

 package com.biubiu.utils;
 
import  Java . io .FileOutputStream;
import java.io.OutputStream;
import java.util.Base64;
 
public class Utils {
 
    /**
     * base64转化成图片文件
     * @param base64
     * @param imgFilePath
     * @return
     */    public static boolean generateImage(String base64, String imgFilePath) {// 对字节数组 字符串 进行Base64解码并生成图片
        if (base64 == null) // 图像数据为空
            return false;
        try {
            // Base64解码
            byte[]  bytes  = Base64.getDecoder().decode(base64);
            for (int i = 0; i < bytes.length; ++i) {
                if (bytes[i] < 0) {// 调整异常数据
                    bytes[i] += 256;
                }
            }
            // 生成 jpeg 图片
            OutputStream out = new FileOutputStream(imgFilePath);
            out.write(bytes);
            out.flush();
            out. close ();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}  

文章来源:智云一二三科技

文章标题:Java之base64转化成图片文件

文章地址:https://www.zhihuclub.com/187369.shtml

关于作者: 智云科技

热门文章

发表回复

您的电子邮箱地址不会被公开。

2条评论

  1. Monitor Closely 1 indomethacin will increase the level or effect of probenecid by acidic anionic drug competition for renal tubular clearance

  2. I ve used soap to calm some of the most vicious and painful leg cramps one could ever suffer

网站地图