1

I've been trying to access images from my assets folder now instead of drawable in order to possibly alleviate some memory issues I'm having.

I found this code to aid with this:

public static Drawable getAssetImage(Context context, String filename) throws IOException {
    AssetManager assets = context.getResources().getAssets();
    InputStream buffer = new BufferedInputStream((assets.open("drawable/" + filename + ".png")));
    Bitmap bitmap = BitmapFactory.decodeStream(buffer);
    return new BitmapDrawable(context.getResources(), bitmap);
}

I'm confused what the context is though. Am I to pass it my MainActivity.java? Or reference it to a specific view? If anyone could explain this I would much appreciate it.

1 Answers1

1

Yes, you can just pass your activity from which you are invoking this method.

Roman Samoilenko
  • 932
  • 12
  • 25