Bitmap is returning null from BitmapFactory.decodeFile(filename)

前端 未结 14 1143
悲哀的现实
悲哀的现实 2020-11-29 04:19

When I am calling this function there is no image in image view bitmapFactory.decodefile(filename) showing null .. please help for this.

Here is my cod

14条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 05:05

    Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
    

    This returns null, if

    1. File paths to the image is wrong
    2. when android cannot decode the bitmap image, so check if you can view the image in other image view software.

    if the above two point are okay in your code, it means you are getting a null value because its taken time for android to render the image.

    add a dummy imageviewer in your code to speed up the render process.

    bm=BitmapFactory.decodeFile(dir.getAbsolutePath());

    imgPassport.setImageBitmap(bm); // This imageviewer is not visible in my App

    Also ensure you are not calling the method decodeFile(dir.getAbsolutePath()) from background thread

提交回复
热议问题