base64解码直方图图像

huangapple go评论71阅读模式
英文:

base64 decoding histogram image

问题

我有一个分析器,它将血液细胞的直方图的base64发送给我(您可以在此处查看https://i.imgur.com/QlIhc6O.png),当我解码base64字符串并直接从中获取图像时,图像无法上传。base64的示例:

AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCws==

我尝试了以下代码:

public static void main(String[] args) {
    String base64Histogram = "AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCwsLCwwPERQZHiMpAA==";

    try {
        // 解码Base64字符串
        byte[] decodedBytes = Base64.getDecoder().decode(base64Histogram);

        // 将解码后的二进制数据保存到图像文件
        String outputFilePath = "histogram.png";//也尝试了jpg格式
        FileOutputStream outputStream = new FileOutputStream(outputFilePath);
        outputStream.write(decodedBytes);
        outputStream.close();

        System.out.println("直方图图像已保存为:" + outputFilePath);
    } catch (IOException e) {
        System.out.println("发生错误:" + e.getMessage());
    }
}

结果是图像已保存但未加载,无法查看。

英文:

I have one analyzer that sends me base64 of histogram of blood cells (you can see here https://i.imgur.com/QlIhc6O.png) , when i decode base64 string and get image directly from it , image cant be uploaded.Example of base64 :

AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCws== 

I tried that

public static void main(String[] args) {
            String base64Histogram = "AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCwsLCwwPERQZHiMpAA==";

            try {
                    // Decode Base64 string
                    byte[] decodedBytes = Base64.getDecoder().decode(base64Histogram);

                    // Save the decoded binary data to an image file
                    String outputFilePath = "histogram.png";//also tried jpg format
                    FileOutputStream outputStream = new FileOutputStream(outputFilePath);
                    outputStream.write(decodedBytes);
                    outputStream.close();

                    System.out.println("Histogram image saved as: " + outputFilePath);
            } catch (IOException e) {
                    System.out.println("Error occurred: " + e.getMessage());
            }
    }

}
result is that image saved but not loaded , it cant be seen

答案1

得分: 1

以下是翻译好的内容:

只是为了展示您拥有的内容,这是我进行base64解码,然后将字节绘制为数据点的结果。我使用Python编写了这段代码,因为从Python绘制更容易:

import base64
import matplotlib.pyplot as plt

inp = 'AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCwsLCwwPERQZHiMpAA=='
x = base64.b64decode(inp)
y = list(x)
plt.plot(y)
plt.show()

输出:
base64解码直方图图像

英文:

Just to show you what you have, here is what I get if I do a base64 decode and then plot the bytes as data points. I wrote this in Python because it's easier to plot from Python:

import base64
import matplotlib.pyplot as plt

inp = 'AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCwsLCwwPERQZHiMpAA=='
x = base64.b64decode(inp)
y = list(x)
plt.plot( y )
plt.show()

Output:
base64解码直方图图像

huangapple
  • 本文由 发表于 2023年7月13日 13:34:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676213.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定