写的Base64 EN $ C $光盘镜像到文件 [英] Write Base64 encoded image to file
问题描述
如何写的Base64 EN $ C $光盘镜像到文件?
How to write Base64 encoded image to file?
我都设有$ C $光盘镜像到使用的Base64为字符串,首先我读文件,然后将其转换成字节数组再申请Base64编码存储图像串。
现在我的问题是如何去code吧。
I have encoded image into string using Base64 for that, First I read the file then convert it into byte array then apply Base64 encoding to store the image string. Now my problem is how to decode it.
byte dearr[] = Base64.decodeBase64(crntImage);
File outF = new File("c:/decode/abc.bmp");
BufferedImage img02 = ImageIO.write(img02, "bmp", outF);
crntImage
是包含字符串重新映像presentation一个字符串变量。
crntImage
is a string variable which contain string representation of image.
推荐答案
假设图像数据已经是你想要的,你不需要的图像格式的ImageIO
在所有 - 你只需要将数据写入到文件中:
Assuming the image data is already in the format you want, you don't need image ImageIO
at all - you just need to write the data to the file:
// Note preferred way of declaring an array variable
byte[] data = Base64.decodeBase64(crntImage);
try (OutputStream stream = new FileOutputStream("c:/decode/abc.bmp")) {
stream.write(data);
}
(我假设你正在使用Java 7的位置 - 如果没有,你需要写一个手动的try / finally语句来关闭流)
(I'm assuming you're using Java 7 here - if not, you'll need to write a manual try/finally statement to close the stream.)
如果该图像数据的不是的你想要的格式,你需要给更多的细节。
If the image data isn't in the format you want, you'll need to give more details.
这篇关于写的Base64 EN $ C $光盘镜像到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!