I select an image from the gallery and I save the path in Sqlite
and up there everything is fine, the problem comes when trying to load the image, it shows ImageView
empty and in Logcat
I receive twice:
Unable to decode stream: java.io.FileNotFoundException:: open failed: ENOENT (No such file or directory)
Make it clear that in Manifest
I have the permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
And in the application I have the permissions granted.
The code when I try to load the image:
private String ruta_imagen = "";
// obtengo todo lo demás correctamente, menos la imagen:
if (notas != null) {
ed_titulo.setText(notas.getTitulo());
ed_nota.setText(notas.getNotas());
tv_fecha.setText(notas.getFecha());
tv_persistente.setText(notas.getPersistente());
tv_categoria.setText(notas.getCategoria());
image1.setImageBitmap(crearThumb());
}
private Bitmap getBitmap(String ruta_imagen) {
// Objetos.
File imagenArchivo = new File(ruta_imagen);
Bitmap bitmap = null;
if (imagenArchivo.exists()) {
bitmap = BitmapFactory.decodeFile(imagenArchivo.getAbsolutePath());
}
return bitmap;
}
private Bitmap crearThumb(){
Bitmap bitmap = getBitmap(ruta_imagen);
BitmapFactory.Options opciones = new BitmapFactory.Options();
opciones.inJustDecodeBounds = true;
BitmapFactory.decodeFile(ruta_imagen, opciones);
int scaleW = opciones.outWidth / 854 + 1;
int scaleH = opciones.outHeight / 480 + 1;
int scale = Math.max(scaleW, scaleH);
opciones.inJustDecodeBounds = false;
opciones.inSampleSize = scale;
opciones.inSampleSize = scale;
bitmap = BitmapFactory.decodeFile(ruta_imagen, opciones);
return bitmap;
}