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 { /** * convert Drawable to Bitmap * @param d * @return */ public static Bitmap drawableToBitmap(Drawable d) { return d == null ? null : ((BitmapDrawable) d).getBitmap(); } 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 | OutOfMemoryError e) { e.printStackTrace(); } finally { try { if (fis != null) { fis.close(); } } catch (Exception e) { e.printStackTrace(); } } return bitmap; } }