【问题标题】:Grails Embed images in csv and xmlGrails 在 csv 和 xml 中嵌入图像
【发布时间】:2013-01-06 11:16:53
【问题描述】:

在 csv 和 xml 中是否有 50x50 的缩略图?我正在使用 grails。

【问题讨论】:

    标签: xml image grails csv groovy


    【解决方案1】:

    您可以将图像转换为 Base64 并嵌入字节数据。这有时在 css 和其他媒体(如数据库)中完成。这是一个简单的例子......

    将图像编码为 CSV 文件...

    def csvFile = new File('my_csv.csv');  
    def imageFile = new File('./images/thumbnail.png');    
    String imageData = imageFile.bytes.encodeBase64().toString();
    
    csvFile.append("${image.name}, ${imageData}"); //<-- write image name and data
    

    解码图像也很容易...

    byte[] imageBytes = imageData.decodeBase64();
    imageFile = new File('./images/decoded/thumbnail.png');
    imageFile.setBytes(imageBytes);
    

    【讨论】:

      猜你喜欢
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 2019-06-10
      • 1970-01-01
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      • 2016-10-29
      相关资源
      最近更新 更多