Glide showing ImageView background in between loading images - android

I've got a simple use case. I have a local image uri (content://path) that I load into an ImageView - that's step 1. After a button is pressed, the image is replaced with an image from our server - that's step 2.
My code is quite simple - or at least, I can reproduce the issue even after I simplified the code to the following:
Glide.with(imageHolder.getContext()).load(url).into(imageHolder);
The first time, this is called with a local uri (content://path), followed by a remote url (http://path.com).
Loading the local uri works just fine. The problem is that, once I initiate the load from the server (which might take a second), Glide rolls back to the ImageView's background image colour. So visually I get old image -> background colour -> new image, which is quite annoying.
Is there some sort of a hidden way in Glide to work around this?

this is because while the server image is being loaded there is a gap between removing local image and showing the new one and that gap is your problem.
one of the workarounds to this issue is to give Glide a placeholder (set your local image as the placeholder) so while Glide is loading image from server it still shows the local image and once the server image is loaded the local one goes away.
Glide.with(imageHolder.getContext())
.placeholder(YOUR_LOCAL_IMAGE_HERE)
.load(url)
.into(imageHolder);

Related

How to display images from URL efficently

I need to display a list of images in my application, and i get those images from an API call as an URL. Now I'm using Glide to show them, but i don't like the loading effect it makes (blank space while loading, and the the image). Is there any way to instant show those images, without any loading time and possibly without downloading them?
Since the images are stored on a remote server there is no way to bypass the downloading process, however Glide makes sure to only download the image from remote server when necessary, as the docs state
By default, Glide checks multiple layers of caches before starting a
new request for an image:
Active resources - Is this image displayed in another View right now?
Memory cache - Was this image recently loaded and still in memory?
Resource - Has this image been decoded, transformed, and written to
the disk cache before? Data - Was the data this image was obtained
from written to the disk cache before? The first two steps check to
see if the resource is in memory and if so, return the image
immediately. The second two steps check to see if the image is on disk
and return quickly, but asynchronously.
If all four steps fail to find the image, then Glide will go back to
the original source to retrieve the data (the original File, Uri, Url
etc).
To resolve this,
but i don't like the loading effect it makes (blank space while
loading, and the the image)
You can instead add a default placeholder on the ImageView until the real image is downloaded. This will display a default image while your actual image is downloading and then after download completion will replace it with the actual one.
Glide
.with(context)
.load(url)
.placeholder(R.drawable.ic_placeholder) //your default placeholder resource
.into(imageView)
you can display images from url by two ways:
Without any third party library:
URL url = new URL("URL of image here");
Bitmap bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bitmap);
Second way is by using Picasso

How to show Glide images when ready? They are shown incorrectly if not fully downloaded

I am working on an application that has this image gallery activity where images are loaded from disk using Glide. These images are downloaded separately through DownloadManager. The problem is that these images might not have been downloaded by the time the user opens the gallery. I guess one way would be to load these images dynamically once each file gets downloaded by going through a BroadcastReceiver but I am wondering if there is an easier solution? Some of the images only shows parts of itself while others don't show at all, and in order to view the full images I have to navigate back into the gallery so that Glide can redo the loading. I would instead like the images to be displayed once they are able to load. I also tried using a placeholder but it will never be replaced by the image (I would also like to avoid using a placeholder image since I don't have any). The images are displayed in a GridView and loaded in getView method of a BaseAdapter. (Currently I also have to avoid storing the images in cache otherwise the incomplete images will be shown the next time as well). Code:
val file = File(urls[position].toString())
Glide.with(context)
.asBitmap()
.load(file)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.fitCenter()
.apply(RequestOptions())
.into(imageView)

RenderScript blur breaks bitmap loaded by Glide

So, the thing is that I am fetching some images using Glide. I fetch them directly into bitmap, and then I blur that bitmap using RenderScript and than show on UI blurred one.
UI itself has "All Images" activity and "Single Image" activity. User clicks on the image on the first activity, and the blurred version is showed on the second one, so it is possible to go back and forth opening and closing the same image.
The issue is that this cause image to become broken, and there is no way to fix it unless you clear all app data.
The issue even survives app reinstall (using Android Studio). So, if I open image, and it is displayed as it should, than make some changes in code, and install the app again, image would show broken immediately after
installation, unless I clear data.
It happens only with bitmaps loaded using glide. If I get some drawable resource as bitmap, everything works well.
UPDATE:
This is the code used here;
Bitmap logo = Glide.with(context)
.load(url)
.asBitmap()
.into(80, 80)
.get();
return BlurBuilder.blur(context, logo);
And BlurBuilder is the class copied from here: Create blurry transparent background effect
Had the same problem. Solved it by setting the Glide decode format to ARGB_8888
https://github.com/bumptech/glide/wiki/Configuration#bitmap-format

ListView images preloading im ImageView without delay (using Picasso or other libs)

I have the problem with image loading in listview. I'm using Picasso to load pictures from network into my imageViews in each row. When I'm scrolling first time there always white background before image loaded in its place. Even if I scroll very slow or even stop scrolling before new item is showing, there still white background showing before the image is loaded. Even if these pictures wasn't taken from the network, but already from cache (yellow indicator). But when these pictures already in memory (green indicator) pictures don't loading each time when scrolling, they already loaded into imageView, so I don't have this white background (or it may appear on fast scrolling, but it's ok).
This how I use Picasso in my adapter:
Picasso.with(context).load(url).fit().centerCrop().into(imageView);
I know this is complicated topic and we can have OOM, but there should be some variants, as I can see it implemented in popular social networks, so I guess it possible.
P.S. fetch() doesn't helped me in this case, changing fit() with harcoded resize(200, 200) method also doesn't helped.
Please write your thoughts without silent minusing this post. Thanks!
Picasso.with("Pass Context") //
.load("Pass URL") //
.transform(new RoundedTransformation(5, 0))
.placeholder(R.drawable.*) //
.error(R.drawable.*) //
.fit() //
.tag(mcontext) //
.into("Your ImageView");

Picasso Square Next Image Cache

I'm using Picasso Square library in my android application. The app is a very simple one and shows a grid of pictures. When you touch one it opens it in full screen and when swiping to the right the next in line should be displayed.
My problem is that for every swipe, the image is loaded by picasso method:
Picasso.with(getApplicationContext()).load(Properties.IMAGE_URL + i).transform(transformation).centerCrop().fit().into(imageView);
I would like to avoid the load wait time and simply cache the next 2 images to be displayed. how would I go about doing this?
I know that picasso caches the images if they were loaded before. Is there a way to load the next image with picasso without attaching it to a specific ui element to be displayed?
There is a way to do it – use fetch(). You can get more information from this question.

Categories

Resources