Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; import android.graphics.Rect; import android.support.v4.util.LruCache; import android.util.DisplayMetrics; import java.io.IOException; import java.io.InputStream; public class Main { private static LruCache<String, Bitmap> drawableCache; private static Bitmap loadAssetBitmap(Context context, String assetPath) { InputStream is = null; try { Resources resources = context.getResources(); Options options = new Options(); options.inDensity = DisplayMetrics.DENSITY_HIGH; options.inScreenDensity = resources.getDisplayMetrics().densityDpi; options.inTargetDensity = resources.getDisplayMetrics().densityDpi; is = context.getAssets().open(assetPath); Bitmap bitmap = BitmapFactory.decodeStream(is, new Rect(), options); if (bitmap != null) { drawableCache.put(assetPath, bitmap); } return bitmap; } catch (Exception e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; } }