base64解码直方图图像

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

base64 decoding histogram image

问题

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

  1. AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCws==

我尝试了以下代码:

  1. public static void main(String[] args) {
  2. String base64Histogram = "AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCwsLCwwPERQZHiMpAA==";
  3. try {
  4. // 解码Base64字符串
  5. byte[] decodedBytes = Base64.getDecoder().decode(base64Histogram);
  6. // 将解码后的二进制数据保存到图像文件
  7. String outputFilePath = "histogram.png";//也尝试了jpg格式
  8. FileOutputStream outputStream = new FileOutputStream(outputFilePath);
  9. outputStream.write(decodedBytes);
  10. outputStream.close();
  11. System.out.println("直方图图像已保存为:" + outputFilePath);
  12. } catch (IOException e) {
  13. System.out.println("发生错误:" + e.getMessage());
  14. }
  15. }

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

英文:

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 :

  1. AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCws==

I tried that

  1. public static void main(String[] args) {
  2. String base64Histogram = "AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCwsLCwwPERQZHiMpAA==";
  3. try {
  4. // Decode Base64 string
  5. byte[] decodedBytes = Base64.getDecoder().decode(base64Histogram);
  6. // Save the decoded binary data to an image file
  7. String outputFilePath = "histogram.png";//also tried jpg format
  8. FileOutputStream outputStream = new FileOutputStream(outputFilePath);
  9. outputStream.write(decodedBytes);
  10. outputStream.close();
  11. System.out.println("Histogram image saved as: " + outputFilePath);
  12. } catch (IOException e) {
  13. System.out.println("Error occurred: " + e.getMessage());
  14. }
  15. }

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

答案1

得分: 1

以下是翻译好的内容:

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

  1. import base64
  2. import matplotlib.pyplot as plt
  3. inp = 'AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCwsLCwwPERQZHiMpAA=='
  4. x = base64.b64decode(inp)
  5. y = list(x)
  6. plt.plot(y)
  7. 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:

  1. import base64
  2. import matplotlib.pyplot as plt
  3. inp = 'AAAADiM9XXCAi5CUlpKLgHduZmBVS0A4MzAuKychHRoZGRkXFBEPDw4ODgwKCggICgoLCwsLCwwPERQZHiMpAA=='
  4. x = base64.b64decode(inp)
  5. y = list(x)
  6. plt.plot( y )
  7. 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:

确定