write Bitmap To File - Android android.graphics

Android examples for android.graphics:Bitmap Load Save

Description

write Bitmap To File

Demo Code

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;

public class Main {

  public static void writeToFile(Bitmap bm, File outupt) {

    FileOutputStream out = null;//from   w ww  . j a  v  a  2  s  . c o m
    try {
      out = new FileOutputStream(outupt);
      bm.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap instance
      // PNG is a lossless format, the compression factor (100) is ignored
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        if (out != null) {
          out.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

  }

}

Related Tutorials