zoukankan      html  css  js  c++  java
  • 将 BufferedImage 对象图片,转成 Base64 编码给前端<img src="编码"/>展示图片用

    直接将处理好的 BufferedImage 对象传入即可

    ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流
                ImageIO.write(bufferedImage, "png", baos);//写入流中
                byte[] bytes = baos.toByteArray();//转换成字节
                BASE64Encoder encoder = new BASE64Encoder();
                String png_base64 = encoder.encodeBuffer(bytes).trim();//转换成base64串
                png_base64 = png_base64.replaceAll("
    ", "").replaceAll("
    ", "");//删除 
    
                
        //        ImageIO.write(bufferedImage, "png", new File("D:/qrcode1.png"));
                System.out.println("值为:"+"data:image/jpg;base64,"+png_base64);

    注意:png_base64 字段,最终要拼接上 

    data:image/jpg;base64,

    才能正常给前端转成图片!

     
  • 相关阅读:
    堆排序算法
    二叉树的创建、遍历(递归和非递归实现)、交换左右子数、求高度(c++实现)
    hdoj1010 奇偶剪枝+DFS
    常见排序算法c++总结
    B
    C
    D
    E
    G
    F
  • 原文地址:https://www.cnblogs.com/xuehuashanghe/p/10300427.html
Copyright © 2011-2022 走看看