create Bitmap From Image File - Android android.graphics

Android examples for android.graphics:Image Load Save

Description

create Bitmap From Image File

Demo Code

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {

  public static Bitmap createBitmapFromImageFile(File imagefile) {
    Bitmap bitmap = null;//from ww  w.j a v  a  2s . c o m
    try {
      FileInputStream fis = new FileInputStream(imagefile);
      bitmap = BitmapFactory.decodeStream(fis);
    } catch (IOException e) {
      e.printStackTrace();
      if (imagefile.exists())
        imagefile.delete();
    }
    return bitmap;
  }

}

Related Tutorials