Android: Display Image from SD CARD

后端 未结 4 1797
栀梦
栀梦 2020-11-27 06:53

This is driving me insane! Here\'s my code (I know this file exists):

File imageFile = new File(\"/sdcard/gallery_photo_4.jpg\");
ImageView jpgView = (Image         


        
4条回答
  •  执笔经年
    2020-11-27 07:06

    I would rather use a BitmapFactory to decode the Image from the file-path:

    Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
    jpgView.setImageBitmap(bitmap);
    

    The Docs say:

    If the specified file name is null, or cannot be decoded into a bitmap, the function returns null.

    Can you check if the code works with another image and if you can open your image on your PC thought. Maybe the file is corrupt.

提交回复
热议问题