Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static File saveBitmap2file(Bitmap bmp) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] byteArray = stream.toByteArray(); File imageFile = null; try { imageFile = File.createTempFile("tempImage" + System.currentTimeMillis(), ".png"); } catch (IOException e) { e.printStackTrace(); } FileOutputStream fstream = null; try { fstream = new FileOutputStream(imageFile); BufferedOutputStream bStream = new BufferedOutputStream(fstream); bStream.write(byteArray); if (bStream != null) { bStream.close(); } } catch (IOException e) { e.printStackTrace(); } return imageFile; } }