Download array of images from array of urls - android

I want to download array of images from my array of urls.
I need to use coroutines and need to know when all images are loaded and stored in one array as bitmaps or drawables.
As for me i researched glide, but didn't find anything useful for my problem cause it download only one image as lazy.
As a result i want to see kotlin coroutine that will download all images and store it in one array.

Try to get Data by url and load image by picasso
Visit https://medium.com/#crossphd/android-image-loading-from-a-string-url-6c8290b82c5e

Related

Load Multiple Images in Android

After calling an API, I get a response of some hundreds of images in the BASE64 format in JSON and I will display them in recyclerview using Glide. Is it an efficient way to get all images in one response and show all images in recyclerview in one shot or do I ask backend developer to send fixed number of images in one response say 10-15 and again make a request when all images are loaded in recyclerview using pagination. Please suggest some best way.
why you store image in BASE64 format on server. change api response and use image url instead of Base64 string. Use picasso for display image in recycleview with resize image.
Add pagination in server api for improve app performance.
It is better to use pagination in RecyclerView so that the user doesn't have to wait for a long time.
You should use pagination to load the data faster and save data. Apart from that if you are using Glide then you dont need the Base64 of image, The url of the image will be enought to diplay the images in the recyclerview.
That will use a lot of memory. Besides, loading hundreds of image will takes longer time, more data and also reduce performance.
Instead of doing that, you can load data from the data source using a load more. If the user wants to load more data then load more data using pagination.

Image URL to create Bitmap android

I have a small problem, as I could convert a url from an image to a bitmap. The url string is obtained through a json that I download with Volley, and I need that bitmap to be able to give a personalized icon to a marker.
I think you can use Picasso Library here, and it will show the image with the given URL dynamically. There is much more benefits of using Picasso. Try that if it helps you.
And also there is no need to download the image to the user. It saves images cache to show the image if user returns in particular time-gap.
Volley supports loading images asynchronously to a bitmap.
Picasso supports loading images asynchronously to a bitmap.
Other image loading libraries may offer similar options, though since you already use Volley and Picasso, you may wish to stick with one of those.

What is the best way to save images in Parse?

What am I trying to achieve: Based on some filters by the app user, I want to return a list with text and images.
How am I doing it: I have created a table in Parse and have added a column with object type as 'file'. I have put all the jpg/gif images into that column. (double-click, browse, select image from local computer).
The trouble I am having is, the list takes considerable time (~7 seconds) before it is displayed on my android app.
Is there a better way of handling image data within Parse or should I store images somewhere else (like Amazon S3)?
I am using standard queries for Parse in order to get data, nevertheless, am also checking if there is any code latency. Wanted to confirm if I am correctly handling the image data for back-end or not.
Is there a better way of handling image data within Parse or should I
store images somewhere else (like Amazon S3)?
If your images is not too much or you are using for example(five image) its better to save the into the Assets or Drawable Folder for loading.
and if i correctly knows about this problem, you need to use ProgressBar and one image, before loading the Images in Internet.
Caching images and displaying
Hope this helps.
I am using Parse to store images too, but it's not slow as you said. Since Parse is part of Facebook, I think their infrastructure is the same. There are possible issues:
Internet connection: Slow or on 3G?
Images: files are big?
Let me know which case you are in.
If you just display thumbnail images, I suggest you to process it before saving to Parse by writing Cloud function as describe on their blog. The you just need to use generated thumbnails on your listview/gridview

Android - Efficient way to load multiple images from remote server

I have an Android application that would retrieve data (images+text) from a php remote server and display them in a GridView.
I am doing the operation in the background using Loaders. I have separate connections for images and texts since retrieving images would take longer and I want to display the texts immediately. The texts are encoded with Json on the server after being retrieved from MySQL. On the app, I am parsing the Json Objects and displaying the texts as I need.
The problem is with images. I am not sure if encoding the images with Json would be a good idea. Also the images are saved as blob in the database, in order to encode them with Json I need to use base64_encode() before which is not efficient. I have seen many posts about this, but it’s always a simple example when you have to get one image. In my case I’ll be retrieving up to 30 small-size images.
My question is, I can proceed with what I just presented, but it seems that there should be a better way to do this. What do you think about this? Am I going the wrong way?
Also I was thinking if I can display each image separately in the gridview once it is ready (not waiting for all the images to be ready) just like in the “Google Play App”’s GridView. What approach can I take to achieve this?
Thanks in advance folks!
Best approach in my eyes would be to download the image files as normal image files via a HTTP get request. Make sure it is threaded of course, and have a thread pool that you can queue up requests into, and have 2-3 threads go through and download.
In terms of saving them, I would personally move away from saving to blob in a database, and opt to save them to the persisted storage in your application's private directory. Saving the image files with their filename as their id in the database you have created will be much quicker for loading them back in.
You can also hold a reference to the ImageView, and have it display a place-holder initially, with a successful HTTP request replacing the bitmap of the ImageView with the one you have just downloaded/read in from storage.
You can also do some image caching within the HTTP request you make.
ImageView myImageView = findViewById(R.id.testImage);
URL url = new URL("http://www.website.com/image.jpg");
URLConnection connection = url.openConnection();
connection.setUseCaches(true);
Object response = connection.getContent();
if (response instanceof Bitmap) {
Bitmap bitmap = (Bitmap)response;
myImageView.setBitmap(bitmap);
}
It also may be helpful to lookup the uses of the LRUCache, which performs a lot of caching functionality for you.
Check out this link at the Android Developer site for a good in depth guide to image caching
Edit:
You can use the advice in Robert Rowntree's answer to load bitmaps more efficiently to cut down on your memory use as well. The link provided details loading of bitmaps using less memory, something that would work well if you are creating thumbnails from larger images downloaded over the web and saved off to local storage.
IMO - there are 2 issues , moving the images across the network to the client and getting them loaded.
Assuming that you are using http as the protocol, you should have a multithreaded solution for http as is available in apache httpclient package. That will get the pictures to the phone fast.
Then , you have to present the pics by getting them into memory and a cache. Here you can consider what 'gallery3D' app does with its grid and bitmaps but its pretty complicated to read thru that code.
check out - http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
check out code samples for loading thumbs from bitmaps.

Storage of Images in DB as URL or blob for android app

I have large amount of pictures in server and need to show up in android app as list view. I tried storing just Url in db, but while retrieving from server it gives an error because of using more number of async task. Any suggestion with regard to this, As it would be useless if i store so many images and if i dont do that, its affecting user experience.
You should not fire up a separate AsyncTask for each image. I suggest that you use a single AsyncTask to retrieve all images, one (or a few) at a time. As each image is received, the AsyncTask can use publishProgress (you will need to override onProgressUpdate) to display it in the UI.
Are you making use of lazy-loading? Whenever you need to load a large, indeterminate number of images it's commonly advised to use lazy loading to both improve user-experience and to solve memory management issues.
Read/watch the following links:
Lazy load of images in ListView
http://www.youtube.com/watch?v=gbQb1PVjfqM

Categories

Resources