Read an Image/file from External storage Android

前端 未结 5 1901
借酒劲吻你
借酒劲吻你 2020-12-03 12:32

I\'m trying to load an image from external storage. I set the permissions, I tried different ways, but none of them works.

BitmapFactory.Options options =          


        
5条回答
  •  一生所求
    2020-12-03 12:41

    File sdCard = Environment.getExternalStorageDirectory();
    
    File directory = new File (sdCard.getAbsolutePath() + "/Pictures");
    
    File file = new File(directory, "image_name.jpg"); //or any other format supported
    
    FileInputStream streamIn = new FileInputStream(file);
    
    Bitmap bitmap = BitmapFactory.decodeStream(streamIn); //This gets the image
    
    streamIn.close();
    

提交回复
热议问题