Show Image View from File Path

Show Image View from file path?

Labeeb is right about why you need to set image using path if your resources are already laying inside the resource folder ,

This kind of path is needed only when your images are stored in SD-Card .

And try the below code to set Bitmap images from a file stored inside a SD-Card .

File imgFile = new  File("/sdcard/Images/test_image.jpg");

if(imgFile.exists()){

Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);

myImage.setImageBitmap(myBitmap);

}

And include this permission in the manifest file:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Is it possible to set image to ImageView from a path (external storage) on Android 10 and higher?

Yes it is possible. first add this line to the application manifest

 android:requestLegacyExternalStorage="true"

in your gradle file set this options(if its not)

 compileSdkVersion 29

and after obtaining permission to use access to memory - you can upload a picture

How to set an image to imageView using filepath in android

If with File you mean a File object, I would try:

File file = ....
Uri uri = Uri.fromFile(file);
imageView.setImageURI(uri);

How to set image path on image view in android

I think you are going to work with JSON,
And load image from server,

If yes than I will suggest you to use any image loader like universal-image loader.

Universal image loader

Android Studio getting image view file path / uri

Hey there this is how i do it, have a try

private void uploadInputStream() {

Uri path = Uri.parse("com.example.project/" + R.id.ivProfilePicture);

Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);

InputStream exampleInputStream = null;
File file = null;

try {
exampleInputStream =
getContentResolver().openInputStream(Uri.parse(bitmap));

file = new File(String.valueOf(inputStream)); //upload the file

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

Let me know how it goes

Can not load image from file path to ImageView with Glide

Just need to add android:requestLegacyExternalStorage="true" to Application tag in Manifest.xml .



Related Topics



Leave a reply



Submit