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
Related
Taking example of viewpager or recyclerview in android we know that they can contain images as well.What i want to know is that how we can load images from database from server and put that images in view pager or recycler view.Upto know my understanding is that i have to make a database in server and put images in it ,now during splash screen download that images and after that put that images into view.Am i going right? Basically what i want to achieve is like shopping app which shows images which changes time to time ? how i can do same ?Do i should go with Rest API to download that images from server and then put in view also do i need to make sure that every time user opens app then it download image?
You can simply fetch .jpg URL from API and then load that image in your app by using Fresco library.
Check this out: Display images with Fresco
First add Fresco to your dependencies in app/build.gradle.
dependencies {
implementation 'com.facebook.fresco:fresco:1.10.0'
}
Don't forget to add in your AndroidManifest.xml proper permission:
<uses-permission android:name="android.permission.INTERNET"/>
Initialize Fresco in class that extend Application class. You can do it in Activity, but it's better to do it just once in Application class.
Fresco.initialize(context);
Instead of ImageView use SimpleDraweeView like this:
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/sdvImage"
android:layout_width="130dp"
android:layout_height="130dp"
fresco:placeholderImage="#drawable/myPlaceholderImage" />
Then just init your SimpleDraweeView object in Activity/ViewHolder/Fragment, parse Url string to Uri like this:
Uri imageUri = Uri.parse("https://i.imgur.com/tGbaZCY.jpg");
And you can set Uri to your SimpelDraweeView object this way:
draweeView.setImageURI(imageUri);
You can use Glide or Picasso as well. Find one that suit your needs by read this post:
Picasso v/s Imageloader v/s Fresco vs Glide
I am migrating android image caching library from picasso to fresco. I want to know if there is any way to invalidate image already catched as I am adding feature to replace existing image there is way to do so in picasso like
Picasso.with(context).invalidate(URI);
This line remove the cached image and use new one using the url provided which is same like,
http://example.com/image_path
In fresco I have tried using
Fresco.getImagePipeline().evictFromMemoryCache(uri);
This is removing image from view but adding same old cached image again and not getting new one from network as it is working in picasso.
Please refer question Invalidate cache in Picasso The accepted answer doing great in case of picasso.
Fresco.getImagePipeline().evictFromMemoryCache(uri);
Above code line remove the image from the catche but image remains there in the disk and render same if called. We need to remove same image from disk as well. Bellow two lines remove the the image from disc cache also we need to remove the small that is thumbnail image if saved from disk cache.
Fresco.getImagePipelineFactory().getMainDiskStorageCache().remove(new SimpleCacheKey(uri.toString()));
Fresco.getImagePipelineFactory().getSmallImageDiskStorageCache().remove(new SimpleCacheKey(uri.toString()));
Note: if you are using custom cache key you need to change it that way.
Try this
public static void clearCache(){
//
ImagePipeline imagePipeline = com.facebook.drawee.backends.pipeline.Fresco.getImagePipeline();
imagePipeline.clearMemoryCaches();
imagePipeline.clearDiskCaches();
// combines above two lines
imagePipeline.clearCaches();
}
message="file:///storage/sdcard0/My Folder/images/Camera_1415795981117.jpg"// image is available at this location
Picasso.with(context).load( message+"")
.into(holder.iv_message_image);
have also tried
message="storage/sdcard0/Fresh IM/images/Camera_1415795981117.jpg";
also tried
message="file://storage/sdcard0/My Folder/images/Camera_1415795981117.jpg";
and also tried with AQuery
aQuery.id(holder.iv_message_image).image(message)
.progress(R.id.pb_loading);
both picasso and AQuery load images from url properly but not from local Please help!
Using Picasso-2.2.0 jar
Thanks in Advance,
Pragna
For your solution this will help. To display image from SDcard you need to convert it to URI first.
Uri uri = Uri.fromFile(new File(message));
Picasso.with(context).load(uri)
.into(holder.iv_message_image);
Must check your image path message is not wrong.
The following code would be very helpful and make sure that you are loading file when you want to load an image from SD card.
Picasso.with(context).load(new File(path)).into(imageView);
This LazyLoading library helps me to load the images from the internet. Can i use this library to load the images from the gallery.
imageLoader.DisplayImage(url, image);
What should i send the argurment to display the image from the gallery
Note I'm having the path of the images in the ArrayList
Imp Note : I'm also having the ArrayList of byteArray (one byte array resembles to one image). So then how can i use the library
Edit I encrypted some images from the gallery and stored in SDCard and i need to display the encrypted images in my app(I know the path of the encrypted images) Encryption is done in Byte[] level.
Please suggest me. ThankYou
Can i use this library to load the images from the gallery?
Gallery itself a application which is showing images from your local folder. So if you have a local image you can show it by its path in your App.
You just need to add file in your image path to make path as URI.
Like
String URL = "file:///mnt/sdcard/image.png"; // from SD card
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);