Loading drawable from sd card

核能气质少年 提交于 2019-11-29 04:40:24

There is actually a BitmapDrawable constructor straight from file path. The method you are using is depricated. Try:

Drawable myDrawable = new BitmapDrawable(getResources(), pathName);

If this doesnt work, Try getting a bitmap and creating a drawable from it:

The bitmap can be created with decodeFile

You can use it like this:

Bitmap myBitmap = BitmapFactory.decodeFile(pathName);

Then you can use the bitmap for drawing etc.

to convert Bitmap to drawable use

Drawable myDrawable = new BitmapDrawable(getResources(), myBitmap);

Take a look Here (Bitmaps) and Here (Bitmap Drawables) for more info.

I am simple do like that

public Drawable getDrawableFromPath(String filePath) {
    Bitmap bitmap = BitmapFactory.decodeFile(filePath);
    //Here you can make logic for decode bitmap for ignore oom error.
    return new BitmapDrawable(bitmap);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!