te33viq|Java如何把二进制数据转换成图片

Ⅰ java如何把二进制数据转换成图片

直接上代码了,应该看得懂吧,str字符串的内容就是你XML里的内容。生成的a.jpeg我也给上传上来了,是个报表噢

importjava.io.File;

importjava.io.FileOutputStream;

importjava.io.IOException;

importsun.misc.BASE64Decoder;

publicclassCodeTest{

publicstaticvoidmain(String[]args)throwsIOException{

Stringstr="hkMyt4m4VkJtstbv8A/1J9hYIAKg6IR2bHx8e+FcGtpiG8drKZ1/+3cqZRLaeZfaKJbanQ6GhoPOMM+mOReiXK9GrEcmdeM6oM6enpq+ml7+fovmZKLeub+mkKvqaM5qztq2treylNLetoc+/25M/S5Tse+rtnGVuy+bW1tvXx93Ywt7azcLk6dzc3PHcp/fkbOPdy9/f3+Dg4O7pjebi0+fj0+Tk5O3pz+3n2uzwrvjpxOrq6vDr2e/v3/Lu3+v2yvLv4O310/Pw3/Pw4PTx4PPx4/Dx8fTy4fXy4fXy5Pbz4vbz4/r3x//n25/n35vr36Pn46Pr46Pf3+Pr56fz46vj49/v56vj4+Pv66vz66fz66vz66/z67Pn+3/366v366/z77P376/377Pr6+v787f///ywAAAAAgwBVAAAI/wD////20XI9ivEunbzVqQaEa/eoDDhmhRckrDEuXf/ilXM+CHixI0Bv50cF2LYx5Ab+++A9/v/c/vC5xdOfcZsEwB7ASZXib3okbzc9T/++++BdrqnlQO5B+WopOYnqaFTihoqpndCqSeZE8H/+6u+//tuch/SfVUVK4XBXvsQ81O+1Cr515f1BNNvCmQVR7Ge+aDz+Z7pMGTzHHyHCMvm4/BHb33Xpu/WPL0TT//++PQbB/PIhGM/vstwCx/4AAgb/B2pY/3L3vxIJzrlOc9/0JueA4l3M4kZzX+wOV/9nmc+mw2PfnTj4MM+aJ/j6e6EKEyhClfIQq4FBAA7";

BASE64Decoderdecoder=newBASE64Decoder();

byte[]bytes=decoder.decodeBuffer(str);

Filefile=newFile("D:/a.jpeg");

FileOutputStreamfos=newFileOutputStream(file);

fos.write(bytes);

fos.flush();

fos.close();

}

}


赞 (0)