Android 4.0 ImageView setImageBitmap does not work

☆樱花仙子☆ 提交于 2019-12-05 13:16:36

I think it's an out of memory problem, you can fix it using this method :

private Bitmap loadImage(String imgPath) {
    BitmapFactory.Options options;
    try {
        options = new BitmapFactory.Options();
        options.inSampleSize = 2;
        Bitmap bitmap = BitmapFactory.decodeFile(imgPath, options);
        return bitmap;
    } catch(Exception e) {
        e.printStackTrace();
    }
    return null;
}

The "inSampleSize" option will return a smaller image and save memory. You can just call this in the ImageView.setImageBitmap :

imgVedio.setImageBitmap(loadImage(IMAGE_PATH));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!