Load Image with Universal Image Loader using the Path of Image - android

I am trying to load an image with UniversalImageLoader. I tried this way:
String path = "/storage/emulated/0/BlackHole/Black Hole/1gatopan0000.png"
ImageLoader.getInstance().displayImage(path, viewHolder.imageView);
But nothing happened. Is it possible to load the image using UniversalImageLoader with the path of the image as a string?

Firstly, you have to add a backslash before any space character in your path.
String path = "/storage/emulated/0/BlackHole/Black\ Hole/1gatopan0000.png"
Then, Picasso is a great library that allows you to load images easily. I personally find it prettier than the UIL. In order to load an image into your ImageView, you simply have to :
Picasso.with(context).load("/your/path/here").into(yourImageView);

Try this:
String path = "/storage/emulated/0/BlackHole/Black\ Hole/1gatopan0000.png"

Related

android Picasso load image from storage

i am using Picasso for load image from web and local storage
for load image from web
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
and for load image from storage i add file:// before path for load image
Picasso.with(context).load("file:///android_asset/DvpvklR.png").into(imageView2);
but when file path have utf-8 charchter with file name its not load the image like file:///android_asset/۲۰۱٧.png
any idea how to solve it every time i want to use picaso its must string path not Uri or File because its saved in sqlite as string
Try this code:
String url = "file:///android_asset/۲۰۱٧.png";
URLEncoder.encode(url, "UTF-8");
Picasso.with(context).load(url).into(imageView2);
try doing
URIUtil.encodeQuery(url)
see the issue at:
https://github.com/square/picasso/issues/652

Android loading local image with space in path and with universal image loader

I am developing android application in which I want to display local image with the help of universal image loader. But when I try to display image which has space in it's local image path then it not able to display image. I tried it in following manner:
Uri.fromFile(new File(newImagePath)).toString();
I am getting following error:
java.io.FileNotFoundException: /storage/emulated/0/WhatsApp/Media/WhatsApp%20Images/IMG-20150421-WA0002.jpg: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:456)
If tried to load image which has no space in its local path then it works fine but image with space in its path cause issue. Need some help. Thank you.
Actually its problem with universal image loader. https://github.com/nostra13/Android-Universal-Image-Loader/issues/371
So you just have decode your image path to remove space.
As per discussion in above link I got the solution :
final String uri = Uri.fromFile(file).toString();
final String decoded = Uri.decode(uri);
ImageLoader.getInstance().displayImage(decoded, imageView);
Can you try to replace space with "\u0020";
path = path.replace(" ","\u0020");

How to load image from SD card using Picasso library

i need to load images from the Sd card into gridview.
For efficiency i'm using Picasso Library
Picasso.with(activity).load(images.get(position).getDataPath())
.resize(96, 96).centerCrop().into(viewHolder.image);
I used the following code in the adapter. unfortunately m unable to see any images
so please can any one help.
Note
And also can anyone suggest any efficient image loading library to load the images from the sd card.
Requirement
I dont to load the image every time when scrolling. If it is already loaded dont load the image on scrolling
To load the file you need to convert it to a uri first
Uri uri = Uri.fromFile(new File(images.get(position).getDataPath()));
Picasso.with(activity).load(uri)
.resize(96, 96).centerCrop().into(viewHolder.image);
Requirement I dont to load the image every time when scrolling. If it
is already loaded dont load the image on scrolling
Picasso is excellent for this
In Picasso version 2.5.2, you need to pass a File as argument to load method, so the image can be loaded as:
Picasso.with(context).load(new File(images.get(position).getDataPath()))
.resize(96, 96).centerCrop().into(viewHolder.image);
I didn't want to create a new File because if the path was already obtained from an existing file, there is no need for a new object (want to see the already existing picture in the device).
According to Picasso docs you have to do something like this:
file:///android_asset/DvpvklR.png
So I used to have:
/storage/sdcard/Pictures/findyoursport/yoursport_1482358052384.jpeg
Prepending: file:// did the trick

displaying image in the imageview directly from the internet

I want to load an image which is located at the url "http://www.Karnatakatourism.org/mm/slide/chickmaglur_home.jpg" onto the imageview in Android.
Can anyone help me with the code to do the same?
You can use android query lib. http://code.google.com/p/android-query/wiki/ImageLoading
You just need to write
aq.id(R.id.imageview_profilee).image("your path");
You can use this one...
There many libs to do this, You can use Picasso.
Here an example of usage:
Picasso.with(context).load("http://www.karnatakatourism.org/mm/slide/chickmaglur_home.jpg").into(imageView);
Or you can use Universal Image Loader class
in which you can use by this one.
imageLoader.displayImage("http://www.karnatakatourism.org/mm/slide/chickmaglur_home.jpg", imageView, options);

How to use Universal image Loader for loading resources locally

I want to know how can i use nostra13 / Android-Universal-Image-Loader for displaying Images locally i.e from drawable folder along with the Memorycache. I want to use it with ViewPager.
any help will be greatly appreciated.
To load images from assets and drawables you should take ExtendedImageDownloader from example project (this class is not a part of library yet) and also set it to configuration.
UPD: Loading local resources (from drawable, assets, content provider) works out of the box since UIL v1.8.0.
See README:
String imageUri = "assets://image.png"; // from assets
String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch)
NOTE: Use drawable:// only if you really need it! Always consider the native way to load drawables — ImageView.setImageResource(...) instead of using of ImageLoader.
Whenever More than one image load from resource dynamically (#runtime) than prefer these one:
String imgUri = "drawable://" + getResources().getIdentifier(imgName, "drawable", getActivity().getPackageName());
Here, imgName = Name of image in resource

Categories

Resources