How can I save the URI of an image once created on android?

0

The following method returns a File, but I can not get it to be set in an imageView

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);

And I do not use the currentBitmap because it is to store a database.

    
asked by JhonArias 13.09.2018 в 16:06
source

1 answer

0

When saving the image, your method returns the Uri in string format:

...
return Uri.fromFile(file).toString();
...

therefore to get the Uri again you can use Uri.parse() , but you must ensure that the value of the string that is actually used is the one obtained by SaveImage() :

  Uri uriImage = Uri.parse(valorSaveImage);
    
answered by 13.09.2018 в 16:35