Android Glide click on item Gridview show image full screen - android

I'm using Glide to download and display images in my gridview. When I click on a item in my gridview I want to display this image in another activity to get this image in full screen. But with Glide I don't know how I can get the image saved in the cache.
Save the image filename in a Database and call again the link to download the image full size with Glide ?
Or try to get the image in the cache but I don't know how to do that.
Could you help me ?

try this code, it's working for me:
On your adapter:
Glide.with(context)
.load("photo_url")
.diskCacheStrategy(DiskCacheStrategy.ALL) //use this to cache
.centerCrop()
.crossFade()
.into(yourImageView);
On your another Activity:
Glide.with(AnotherActivity.this)
.load("photo_url")
.diskCacheStrategy(DiskCacheStrategy.ALL) //use this to cache
.crossFade()
.into(yourImageView);
Use .diskCacheStrategy(DiskCacheStrategy.ALL) to cache & don't forget to make image scaling same. It will working.

Related

How to stop refreshing gif image when reload

I am trying to load .gif file in ImageView using Glide. It loads properly but when the .gif file reload then the image refreshes like jerking or bouncing. But I want to stop this refreshing. The .gif file works properly in browser and photo viewer. My code is:
Glide.with(context)
.load(R.raw.white_bg1)
.into(new GlideDrawableImageViewTarget(holder.imageview));
Any idea how to solve this?
Try this:
Glide.with(context)
.load(R.raw.white_bg1)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.skipMemoryCache(true)
.into(holder.imageview)

RecyclerView or Glide doesn't update image when the image is overwritten

I use Glide in onBindViewHolder() method in an adapter extended from RecyclerView.Adapter as follows:
Glide.with(context)
.load(imagePath)
.override(500, 500)
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.into(((MyItemHolder) holder).imageView);
Then, I do cropping in one of the images that are given as data to the adapter. After cropping image, I overwrite the image file, i.e., I save the edited image with the same filename. So the imagePath stays the same whereas the image has changed. However, this change isn't being reflected in the RecyclerView even with a separate notifyDataSetChanged() call. The change reflected if I save the edited image with a different filename.
Is there any way to achieve detection of the image content change while keeping filename same?
The reason this is happening is because Glide is caching the image and as the path is same so it will not get to know about the change. For this to work you need to change the caching strategy and skip the memory cache like this:
Glide.with(context)
.load(imagePath)
.override(500, 500)
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(((MyItemHolder) holder).imageView);
Now the image will not get cached and the image will get updated.

Loading image in android imageview

How to load images in same image view from web or local android gallery?
I have an image view which has three options for loading images templates from web service,from gallery, from camera.I am using Glide library to load images from web service, Now, if i load image from web by glide and remove that image by remove button which i have for removing a picture after i pick image from gallery it doesn't load the image from gallery instead load the same image from glide which i removed before.
write the code like this for loading image .
Glide.with(mContext).load(imgUrl)
.thumbnail(0.5f)
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
Glide Library Intoduction Go through with this link, hope it will be work
You can use Picasso library. Image loading using Picasso is very easy, you can do it like this way
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
and in their website you can get every details.
and another Library is Glide. You can use Glide too for loading image..
You can also use Glide:
Glide.with(context).load(image).asBitmap().placeholder(R.drawable.placeholder).error(R.drawable.error).into(imageview);

Android Glide: Show a blurred image before loading actual image

I am developing an Android app which displays full screen images to the user. Images are fetched from the server. I am using Glide to show the image. But I want to display a very small size blurred image before displaying the actual image. Once the image is cached, directly full sized image should be shown.
Image Displaying flows goes like this:
- If image is downloaded for the first time, first download a small scaled image, and then download full resolution image.
- If image has been downloaded before, directly show full scale image.
I cannot find any method in Glide library, which tell me if a file exist in cache or not.
Any idea, how this can be done.
Glide.with(context.getApplicationContext())
.load(Your Path) //passing your url to load image.
.override(18, 18) //just set override like this
.error(R.drawable.placeholder)
.listener(glide_callback)
.animate(R.anim.rotate_backward)
.centerCrop()
.into(image.score);
with Glide v4:
Glide.with(context)
.load(URL)
.thumbnail(0.1f)
.into(image_view)
Better you can get idea from this Library or Use this library.
2 ways to do Blur and Original image in Android.
1) Initially load Blur Image Server URL path and once get success bitmap caching mechanism to load Original(Large) Image Server URL path.
Point 1 is possible, I got answer for you( Ask your server team to get Blur image or Low quality image to make blur and then load large image).
APK Link
Glide.with(mContext)
.load(image.getMedium())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
// Do something with bitmap here.
holder.thumbnail.setImageBitmap(bitmap);
Log.e("GalleryAdapter","Glide getMedium ");
Glide.with(mContext)
.load(image.getLarge())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
// Do something with bitmap here.
holder.thumbnail.setImageBitmap(bitmap);
Log.e("GalleryAdapter","Glide getLarge ");
}
});
}
});
2) Fresco by Facebook is a new image library for Android. Here’s the official blog post introducing the library. It supports the streaming of progressive JPEG images over the network which can be really helpful to display large images over slow connections. One can see the image gradually improve in quality.
Progressive JPEGs with Facebook Fresco
Use BitmapFactory.Options.inSampleSize to make a downsampled version of the image, and upload both versions. Load the sample image (which should take less time) and when the bigger version is downloaded, switch to that. You could also use a TransitionDrawable to make a fade transition.
this is not a perfect way but it will be easiest way to make it.
make placeHolder image as blur and set it into glide. then always it will show blur image and then after load the actual image it will appear.
you can refer this code to use glide.
//crete this method into your Utils class and call this method wherever you want to use.
//you can set these placeHolder() and error() image static as well. I made it as comment inside this method, then no need to use [placeHolderUrl and errorImageUrl] parameters. remove it from this method.
public static void loadImage(final Activity context, ImageView imageView, String url, int placeHolderUrl, int errorImageUrl) {
if (context == null || context.isDestroyed()) return;
//placeHolderUrl=R.drawable.ic_user;
//errorImageUrl=R.drawable.ic_error;
Glide.with(context) //passing context
.load(getFullUrl(url)) //passing your url to load image.
.placeholder(placeHolderUrl) //this would be your default image (like default profile or logo etc). it would be loaded at initial time and it will replace with your loaded image once glide successfully load image using url.
.error(errorImageUrl)//in case of any glide exception or not able to download then this image will be appear . if you won't mention this error() then nothing to worry placeHolder image would be remain as it is.
.diskCacheStrategy(DiskCacheStrategy.ALL) //using to load into cache then second time it will load fast.
.animate(R.anim.fade_in) // when image (url) will be loaded by glide then this face in animation help to replace url image in the place of placeHolder (default) image.
.fitCenter()//this method help to fit image into center of your ImageView
.into(imageView); //pass imageView reference to appear the image.
}
glide has a direct way of doing this :
val thumbnailRequest = Glide.with(this)
.load("https://picsum.photos/50/50?image=0")
Glide.with(this)
.load("https://picsum.photos/2000/2000?image=0")
.thumbnail(thumbnailRequest)
.into(imageThumbnail)
from the blog:
Thumbnails are a dynamic placeholders, that can be loaded from the Internet. Fetched thumbnail will be displayed until the actual request is loaded and processed. If the thumbnail for some reason arrives after the original image, it will be dismissed.
You must have a small-size and a full-size image on your server. You can use Firebase Resize Image Extension if you are using Firebase as your backend. Once you have a small-size image URL and a full-size image URL you can use Glide like this:
Glide.with(context)
.load(fullSizeImageUrl)
.thumbnail(
Glide.with(context)
.load(smallSizeImageUrl)
).into(imageView)
You'll get that blurry effect as the small-size image will be blurry
According to Glide Doc:
.thumbnail()
loads and displays the resource retrieved by the given thumbnail request if it finishes before this request. Best used for loading thumbnail resources that are smaller and will be loaded more quickly than the full size resource. There are no guarantees about the order in which the requests will actually finish. However, if the thumb request completes after the full request, the thumb resource will never replace the full resource.
use BitmapFactory.Options.inSamleSize to load a downsampled version of the image. Then load the bigger image and do a fade transition using a TransitionDrawable
Hope this will Helps you ! Cheers !

Loading Image orientation wrong

Hi I used the picasso library for load the image from server url. But some of images loading in wrong orientation. ExifInterface is class to find out the image orientation but here image is not in resource folder. I have only image url but i want to show the image in correct orientation. How I can achieve to show the image on imageview with correct view.
Picasso.with(context)
.load(url)
.resize(200, 200)
.centerCrop()
.placeholder(R.drawable.ic_pic)
.error(R.drawable.ic_pic)
.into(holder.image);

Categories

Resources