E / BitmapFactory:无法解码流:java.io.FileNotFoundException:下载/my_file.JPEG(无此类文件或目录)

时间:2019-11-25 13:41:40

标签: android android-studio bitmap android-bitmap

我已经尝试了每种方法,但是没有输出。它显示了我尝试过各种方式的错误。

File imgFile = new File( Environment.DIRECTORY_DOWNLOADS, "/my_file.JPEG");
    if(!(imgFile==null)){
        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getPath());
        myImage.setImageBitmap(myBitmap);
        Log.d("ashwiniiii","ashwiniii");
    }
    else {
        myImage.setImageResource(R.drawable.ic_launcher_background);
    }

1 个答案:

答案 0 :(得分:0)

 File imgFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

    if(!(imgFile==null)){
        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getPath() + "/my_file.JPEG");
        myImage.setImageBitmap(myBitmap);
    }
    else {
        myImage.setImageResource(R.drawable.ic_launcher_background);
    }