-1

I need to show image from the File type, this my code snippet :

//Part 1 how I'm setting my file (picking image from gallery)
    currImageURI = data.getData();
    myImage= new File(currImageURI.getPath());

//Part 2 how I'm trying to show my image from the File
ImageView iv = (ImageView) findViewById(R.id.imageView);
iv.setImageURI(Uri.fromFile(myImage));

This is the value of myImage while debuging :

path : /document/image:19144

This is valid path and valid Image, but I got this Error :

resolveUri failed on bad bitmap uri: file:///document/image%3A19144

So what's the problem over here ? I h've to use the FILE type. Show image from File type .

Chlebta
  • 3,090
  • 15
  • 50
  • 99

2 Answers2

0

Try with:

ImageView.setImageUri(Uri.fromFile(new File("/path/to/image")));

Or with:

ImageView.setImageUri(Uri.parse(new File("/path/to/image").toString()));

Updated

Uri imageUri = data.getData();
InputStream imageStream = null;
try {
    imageStream = getContentResolver().openInputStream(imageUri);
    ImageView imageView = (ImageView) findViewById(R.id.imgView);
    imageView.setImageBitmap(BitmapFactory.decodeStream(imageStream));
} catch (FileNotFoundException e) {
    // Handle the error
} finally {
    if (imageStream != null) {
        try {
            imageStream.close();
        } catch (IOException e) {
            // Ignore the exception
        }
    }
}
Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
-1

This is how I have done it. Try it once

Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();

        ImageView imageView = (ImageView) findViewById(R.id.imgProfilePic);
        imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
surhidamatya
  • 2,419
  • 32
  • 56
  • I need to correct my code not to change the hole code – Chlebta Nov 18 '14 at 12:05
  • @Chlebta can u check this lnk http://stackoverflow.com/questions/5095676/resolveuri-failed-on-bad-bitmap-uri-when-putting-image-on-listview and http://stackoverflow.com/questions/17334529/setting-imageview-image-using-path-of-file-from-external-storage?rq=1 – surhidamatya Nov 18 '14 at 12:12