load Image From Asserts - Android android.graphics

Android examples for android.graphics:Image Load Save

Description

load Image From Asserts

Demo Code

import java.io.IOException;
import java.io.InputStream;

import android.content.Context;
import android.graphics.drawable.Drawable;

public class Main {

  public static Drawable loadImageFromAsserts(final Context ctx, String fileName) {
    try {//from w  w w  . j  a  v  a2  s  .co  m
      InputStream is = ctx.getResources().getAssets().open(fileName);
      return Drawable.createFromStream(is, null);
    } catch (IOException e) {
      if (e != null) {
        e.printStackTrace();
      }
    } catch (OutOfMemoryError e) {
      if (e != null) {
        e.printStackTrace();
      }
    } catch (Exception e) {
      if (e != null) {
        e.printStackTrace();
      }
    }
    return null;
  }

}

Related Tutorials