Sunday 9 June 2013

Bitmap to File in Android

File f = File(context.getCacheDir(), filename);
f.createNewFile();

Bitmap bitmap = your bitmap;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();


FileOutputStream fos = new FileOutputStream(f);
fos.write(bitmapdata);