android如何由数组保存成图片并保存在SD卡上

2024-12-15 16:37:34
推荐回答(1个)
回答1:

Bitmap bm = BitmapFactory.decodeByteArray(byte[] data, int offset, int length);别忘了判断数组是不是为空。

保存。。。。
public void saveFile(Bitmap bm, String fileName) throws IOException {
private final static String ALBUM_PATH
= Environment.getExternalStorageDirectory() + "/download_test/";

File dirFile = new File(ALBUM_PATH);
if(!dirFile.exists()){
dirFile.mkdir();
}
File myCaptureFile = new File(ALBUM_PATH + fileName);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
bos.flush();
bos.close();
}