Skip to content Skip to sidebar Skip to footer

Android: Filenotfoundexception On An Image In Drawable

I'm trying to use this code that I've seen on multiple posts throughout stackoverflow public static Bitmap loadBitmap(Context context, String filename) throws IOException {

Solution 1:

The AssetManager is intended to access the data in the assets folder. So in your example, it looks for assets/drawable/filename and does not find anything.

To get a resource from drawable, one should use

Drawabled= getResources().getDrawable(R.drawable.filename);

If you're sure it's a bitmap, you can do it like so:

Bitmapbm= ((BitmapDrawable)getResources()
                .getDrawable(R.drawable.filename)).getBitmap();

Solution 2:

You can do it like this...

// load image from Assets folder// get input streamInputStreammIms= getAssets().open("ic_launcher.png");
        // load image as DrawableDrawablemDraw= Drawable.createFromStream(mIms, null);
        // set image to ImageView
        mIms.setImageDrawable(mDraw);

Post a Comment for "Android: Filenotfoundexception On An Image In Drawable"