首页 > 解决方案 > 如何保存 Uri 表单图像?

问题描述

我想从保存在内部存储器中的图像中保存 Uri 或 pathc,以便在获取并放入 viewImage 表单毕加索之后,但这不起作用。

public File SaveImage(Bitmap ImageToSave) {

    String file_path = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + NameOfFolder;

    String CurrentDateAndTime = getCurrentDateAndTime();
    File dir = new File(file_path);
    if (!dir.exists()) {
        dir.mkdirs();
    }
    File file = new File(dir, NameOfFile + CurrentDateAndTime + ".jpg");
    try {
        FileOutputStream fOut = new FileOutputStream(file);
        ImageToSave.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
        fOut.flush();
        fOut.close();
        MakeSureFileWasCreatedThenMakeAvabile(file);
        AbleToSave();
    }
    catch(FileNotFoundException e) {
        UnableToSave();
    }
    catch(IOException e) {
        UnableToSave();
    }

    //return file.getPath();
    //return file.getAbsolutePath();
    return file;
}

我保存图像。

File file = saveImage(currentBitmap);


Picasso.get().load(file.getAbsolutePath()).into(imageView);

但永远不要加载图像

注意:currentBitmap 不能使用(因为它是为了保存在 Realm 数据库中,占用空间很大)。

谢谢你的支持。

标签: androidimageviewuri

解决方案


推荐阅读