Android:当我试图保存位图时ENOENT

时间:2017-09-30 09:09:56

标签: android bitmap io

我是每个人,

当我尝试保存我在智能手机上下载的位图时出现此错误:

09-26 16:10:46.981 11106-11106/woowin.woowin W/System.err: java.io.FileNotFoundException: /storage/6535-6234/saved_images/photo_profil.jpg: open failed: ENOENT (No such file or directory)

...

我下载此图片在我的个人资料中有一个jpeg文件,我尝试将其保存在特定文件中。我用这个课:

public class DownloadImage extends AsyncTask<String, Void, Bitmap>{
    ImageView bmImage;

    public DownloadImage(ImageView bmImage){
        this.bmImage = bmImage;
    }

    protected Bitmap doInBackground(String... urls){

        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try{
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        }catch (Exception e){
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return mIcon11;
    }

    protected void onPostExecute(Bitmap result){
        bmImage.setImageBitmap(result);
        saveImage(result,"photo_profil");
    }

}
private void saveImage(Bitmap finalBitmap, String image_name) {


    String root = Environment.getExternalStorageDirectory().getAbsolutePath();
    File myDir = new File(root + "/saved_images");
    myDir.mkdirs();

    String fname = image_name +".jpg";
    File file = new File (myDir, fname);
    if (file.exists ()) file.delete ();
    try {
        FileOutputStream out = new FileOutputStream(file);
        finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
        out.flush();
        out.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

我在互联网上搜索了一个回复,我实施了正确的权限:      问题出在哪儿 ?

我需要将图片保存在本地存储上。并创建一个特定的文件夹。 谢谢回复

0 个答案:

没有答案