I have a list of photos that I want to display so I am using a RecyclerView and a RecyclerView.Adapter. So when I bind the view in onBindViewHolder(), I do something like this:
// photo is a Object that contains a url
// photoViewHolder.photo is the imageview
Glide.with(photoViewHolder.photo.getContext()) //use the imageview context
.load(photo.getPhotoScaledURL())//load the photo using an url
.into(photoViewHolder.photo); //into the imageview
But here I am always relying on the URL. Would I be able to somehow always have this image cached? Or is there a better way to do this?
To show some of the images offline first download your image and store the path in DB.Now whenever you offline show the downloaded image.And when online just check the whether image is already downloaded or not, If downloaded then show downloaded image else use glide.
Related
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
I am new in android app developing and got stuck in this problem. To understand my problem -
Let, I am a developer and I have an app. The app has a imageview. In that imageview, the image will be loaded using glide load(url) method from my(developer) website. Now I(developer) want to change the image that will be shown in the app same imageview. But if I change the image the image url will be changed and glide load(url) method will not be able to download new image? How can I solve this problem or what topic should learn to handle this issue or what is the alternative?
Download image
Save to disk (optional)
Modify image (optional)
Show modified image in ImageView.
(You don't need glide here)
we are using an app for setting wallpaper in android device, for that we are doing below steps
1) we have set of images and URLs
2) We are fetching the URL on an Imageview
so now we have to set the wallpaper, for that we need the image file, which is the best way to do it?
1) Download the file directly from URL and store it in a local storage and use it as wallpaper.
or
2) Create a bitmap from the Imageview and use it as wallpaper.
Doing the second option will reduce any quality of the image we using?
First option how to we can do it?
We have fetch the images successfully inside the application.
Always prefer to cache your image downloads so that you don't have to repeat the task. Using libraries like Picasso or Glide reduces a lot of effort is handling your images while at the same time optimizing your code.
Additionally it's best to use the original image as wallpaper rather than consuming the image view because if you have set any scale type's on your image view then your image will be cropped.
Picasso allows for hassle-free image loading in your application—often in one line of code!
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
I am working on a simple app and I am having issues understanding how to use volley for something I feel should be an easy task. Currently I have gotten volley to grab a json array that populates a list of images with titles next to them. The problem is I want to be able to press on an item in the list and spawn a new fragment with a larger version of the image in it. This seems like a really basic task, but I can't seem to find the right way to do it. If I grab the full images to create the list view, I run out of memory. I started grabbing thumbnail images, but then when I create the fragment, the view is inflated before the request for the image finishes. What is the right way to do this?
You can specify a placeholder image while Volley downloads your image, and an error image if the download wasn’t successful. In your situation, you can use your thumbnail image as the placeholder image.
The Making Image Request section in this artcle shows the good way to handle image request with Volley.
Sample code:
// Loading image with placeholder and error image
imageLoader.get(Const.URL_IMAGE, ImageLoader.getImageListener(
imageView, YOUR_THUNMBNAIL_IMAGE, R.drawable.ico_error));
I want to display thumbnail image as image icon in ListView.
I am using array list that contains all thumbnail images path, these path will be accessed from the server.
My arraylist as ahown below.
mylist=['a1','a2','/playback/2012/a1.jpg','b1','b2','/playback/2012/000_b1.jpg', .....]
In this nearly 15 paths are there.. Now i want to display these images in listview.
'a1' is videoName 'a2' is categoryName and one more is path.
These path will be accessed from server only.. I think, we can't store it in drawable.
These are always changing.
How to solve it?
Please help me.
Use ImageView in the layout for ListView items and load images as described here:
How to load an ImageView by URL in Android?
and optionally here:
Lazy load of images in ListView