Android: FileNotFoundException on an image in drawable -


i'm trying use code i've seen on multiple posts throughout stackoverflow

    public static bitmap loadbitmap(context context, string filename) throws ioexception {            assetmanager assets = context.getresources().getassets();            inputstream buf = new bufferedinputstream((assets.open("drawable/" + filename)));            bitmap bitmap = bitmapfactory.decodestream(buf);             return bitmap;    } 

but i'm getting "filenotfoundexception: drawable/filename". have file name i'm trying load in drawable folders. ideas? i've tried , without file extension, tried putting file every folder , tried multiple phones/emulator.

the assetmanager intended access data in assets folder. in example, looks assets/drawable/filename , not find anything.

to resource drawable, 1 should use

drawable d = getresources().getdrawable(r.drawable.filename); 

if you're sure it's bitmap, can so:

bitmap bm = ((bitmapdrawable)getresources()                 .getdrawable(r.drawable.filename)).getbitmap(); 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -