Skip to content

Instantly share code, notes, and snippets.

@iammert
Created November 10, 2016 08:42
Show Gist options
  • Save iammert/5ccf8b8cf799d961602e4b93d3cf7640 to your computer and use it in GitHub Desktop.
Save iammert/5ccf8b8cf799d961602e4b93d3cf7640 to your computer and use it in GitHub Desktop.
private static File bitmapToFile(Context context, Bitmap bitmap, String fileName) throws IOException {
File f = new File(context.getCacheDir(), fileName);
f.createNewFile();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 50 , bos);
byte[] bitmapdata = bos.toByteArray();
FileOutputStream fos = new FileOutputStream(f);
fos.write(bitmapdata);
fos.flush();
fos.close();
return f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment