英文:
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()
英文:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论