Opening a File from assets folder in android

These Lines are working perfectly–

InputStream assetInStream=null;

try {
    assetInStream=getAssets().open("icon.png");
    Bitmap bit=BitmapFactory.decodeStream(assetInStream);
    img.setImageBitmap(bit);
} catch (IOException e) {
    e.printStackTrace();
} finally {
    if(assetInStream!=null)
    assetInStream.close();
}

If your image is very big then you should scale your image before decoding it into Bitmap. See How to display large image efficiently

Leave a Comment