I am using Glide library for displaying image from url in recyclerView ,
Glide.with( context )
.load(url).placeholder(R.drawable.default_user_picture)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.crossFade()
.into(iv);
but since I want to print the bitmap from my app , I also want to get the bitmap of the image cached by Glide, so How to get the bitmap if we specify the url of the image that is already Cached?
Related
I am developing A App which requires loading multiple images from their urls. I save all the images in firebase storage. I am currently using a compressor to reduce the size.
newImageFile=new File(uri1.getPath());
try {
compressedImageFile = new Compressor(ProductAdd.this)
.compressToBitmap(newImageFile);
} catch (IOException e) {
e.printStackTrace();
}
baos = new ByteArrayOutputStream();
compressedImageFile.compress(Bitmap.CompressFormat.JPEG, 100, baos);
thumbData1 = baos.toByteArray();
and I using Glide to load the image from the url
Glide.with(context).load(imgUrl).into(holder.cutImg);
I wanted to know if there is any way I could improve to load images much faster. Maybe store them in a specific format.
You can load a thumbnail of the original image into the ImageView before the original image loads.
Glide.with(fragment)
.load(url)
.thumbnail(0.05f)
.into(imageView);
This will load the 5% quality of the original image into the view and when the complete image loads it will be replaced.
And if you're having a separate URL for thumbnail then
Glide.with(fragment)
.load(url)
.thumbnail(
Glide.with(fragment)
.load(thumbnailUrl))
.into(imageView);
Now when image loads it will be immediately loaded into the view, here you can use the transition for a smooth effect.
Glide.with(fragment)
.load(url)
.thumbnail(0.05f)
.transition(DrawableTransitionOptions.withCrossFade())
.into(view);
You can checkout my project in which I'm also first compressing the Image and storing a thumnail image to Firebase Storage and then loading it.
You can also try different DiskCacheStrategies but I would suggest to go with the default one, it works just fine!
Here are various DiskCacheStrategies:
.diskCacheStrategy(DiskCacheStrategy.ALL)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
You can use the disc strategy which will be used to store the image on the disc. So it may take time for loading at first but later it does not take time at all.
For Glide 4.x
Glide
.with(context)
.load(imgUrl)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.into(holder.cutImg);
For Glide 3.x
Glide
.with(context)
.load(imgUrl)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(holder.cutImg);
Please note: This will not refresh the image if you just update the image without updating URL. SO if you want to see the updated image you must update URL and Glide will automatically download an image for you.
if you are using firebase storage for host your images : Using FirebaseUI you can quickly and easily download, cache, and display images from Storage with Glide. source
Glide.with(context).load(model.imageUrl).thumbnail(0.05f).into(holder.imageView)
I am loading an image from remote URL into an ImageView with Glide. When I update the image, the content within that URL changes, but the URL location remains same. (This is as expected).
for eg. https://www.the-android-app.com/userid/121.jpg
Now I am showing image into ImageView using this code.
Glide
.with(this)
.load(profilePicUrl) //this is in String format
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.skipMemoryCache(true)
.error(R.drawable.default_profile_pic)
.into(imgProfilePic);
When I update my profile pic, Glide is loading the same old pic from Cache. I need to remove cache entry for this URL before fetching the new image.
Edit:
The url always remains same, only the content inside it changes.
I'm using Glide 3.8.0
You can try signature(new ObjectKey(System.currentTimeMillis()))
Look in Custom cache invalidation for more information.
Example
GlideApp.with(this)
.load(imageUrl)
.signature(new ObjectKey(System.currentTimeMillis()))
.into(imageView);
I'm looking into using Glide to access gifs off an image hosting website instead of having them all stored in the app within the assets folder. I have Glide working in the sense that it will load the image I specify when the original URL fails.
ImageView imageViewGif = (ImageView) findViewById(R.id.gif);
String gifUrl = "http://imgur.com/gallery/XgbZdeA";
Glide
.with(this)
.load(gifUrl)
.asGif()
.error(R.drawable.alternator_pic)
.into(imageViewGif);
So it loads up alternator pic just fine but I am unable to get it to load an image or gif from the specified URL. What am I missing?
i have listview to load images for alot of users and this listview item has an imageview for profile picture of user, the problem here if the user changed his the new image will not be shown as last profile picture is cached and the old one will be displayed because the new and old image have the same url:
URL EX:
"https://xyz.s3.amazonaws.com/users/" + friend_id + "/photos/profile.jpg"
i used Glide but i have the same problem
This issue is because of the cache of images, Glide checks if image is available in cache, if it does glide loads it else it would load the new image.
To solve this issue you need to change its cache strategy like this
Glide.with(mContext)
.load((Integer) mDataset.get(position))
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.NONE) // this will prevent image to be cached and each time glide will load it from server
.into(imageView);
When i load bitmap it shows cannot resolve load(android.Graphic.Bitmap), is there any alternative to show bitmaps in imageview.
Picasso.with(mContext.getApplicationContext())
.load(model.getBitmap()) // return Bitmap object
.resize(100, 100)
.centerCrop()
.into(holder.mAlbumImage);
Picasso image loader is good but there are also many image loader which are better than picasso like.
Universal ImageLoader
Facebook fresco