Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import java.io.FileInputStream; import java.io.FileNotFoundException; public class Main { public static final Bitmap getBitmap(Drawable dr) { if (dr == null) { return null; } if (dr instanceof BitmapDrawable) { return ((BitmapDrawable) dr).getBitmap(); } return null; } public static Bitmap getBitmap(Context context, String fileName) { FileInputStream fis = null; Bitmap bitmap = null; try { fis = context.openFileInput(fileName); bitmap = BitmapFactory.decodeStream(fis); } catch (FileNotFoundException e) { } catch (OutOfMemoryError e) { } finally { try { fis.close(); } catch (Exception e) { } } return bitmap; } }