public void buildFile(String finalPath, String content) throws Exception {
byte[] data = null;
data = content.getBytes();
String imgStr = new String(data);
BASE64Decoder decoder = new BASE64Decoder();
byte[] b = decoder.decodeBuffer(imgStr);
for (int i = 0; i < b.length; ++i) {
if (b[i] < 0) {
b[i] += 256;
}
}
Bitmap bm = BitmapFactory.decodeByteArray(b, 0, b.length);
File f = new File(finalPath);
f.createNewFile();
FileOutputStream fOut = null;
fOut = new FileOutputStream(f);
bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
if(fOut!=null){
fOut.close();
}
}
base64解码后转成图片到本地
最新推荐文章于 2024-04-08 16:34:57 发布