/**
* 将bitmap保存到本地
*/
public static File saveImg(Bitmap b, String outPath, int q) {
File mediaFile = new File(outPath);
try {
if (mediaFile.exists()) {
mediaFile.delete();
}
if (!mediaFile.getParentFile().exists()) {
mediaFile.getParentFile().mkdirs();
}
mediaFile.createNewFile();
FileOutputStream fos = new FileOutputStream(mediaFile);
b.compress(Bitmap.CompressFormat.JPEG, q, fos);
fos.flush();
fos.close();
b.recycle();
b = null;
System.gc();
return mediaFile;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 将bitmap转化成二进制流进行传递
*/
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] datas = baos.toByteArray();
Intent intent = getIntent();
intent.putExtra("bitmap", datas);
byte[] b = intent.getByteArrayExtra("bitmap");
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);