Android: recover an image which it has been loaded - android

I want to load and scale an image from an URL in a imageView.
Then, when user touch that image, I want to load the image (without scale) in other imageView or webView for example.
The problem is that I don't want load image twice. The first time, it download in somewhere (cache?) and I want recover for not doing two request...
some example? suggestion?
thanks

you should consider to load first just a thumbnail of the image and wait with downloading the real one until the user really wants to see it.
for caching see LruChache

This tutorial should help with caching: http://codehenge.net/blog/2011/06/android-development-tutorial-asynchronous-lazy-loading-and-caching-of-listview-images/
If you have lots of images, consider using an LruCache. It helps manage large amounts of cache data.

Related

Android View pager load image one by one on swipe through next page

I need to show 1000 images in viewpager from DB.The problem is if I fetch all images from DB and try to set those images to adapter,it shows Bitmap out of memory exception since heap size gets exceeded. So,I'm trying other way around which is to load images one by one when the user swipes to next page.I Googled a bit,but didn't find any appropriate solution.so any input on this is highly appreciated.
Here is all that you need : http://developer.android.com/training/displaying-bitmaps/index.html
Load Bitmaps efficiently, LRU cache, etc. etc.
To summarize, you should fetch one bitmap at a time, scale it down using inSampleSizeand use LRUCache. OR, you can use http://code.tutsplus.com/tutorials/android-sdk-working-with-picasso--cms-22149 library

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.

How to handle Android ListView having more than 15000 bitmaps of size 100kb

I am getting URL string of image in one response, Then i am downloading those images and converting tobitmaps then displaying in listview.
Here my question is in future listview items may increase upto 50000,in this case how can i handle data in listview for smooth scroll without giving ANR Exception.Please provide some sample code.
Dont Load All Images At a Time.... It will cause OutOfMemoryException..you can load images in number of pages from URL....
To download images from URL you can use Picasso library...
It helps you to avoid OutOfMemoryException and store cache of images too..
You can use LAZY LOAD... and you can try this code for download images...
Picasso.with(context).load(URL).fit().centerCrop().into(imageView);
Simple answer dont make a listview so big. 50K elements in a single screen is never a good idea in any scenario(web, desktop or mobile). My suggestion is to have some sort of pagination just like in websites. As for the images like #Prag suggested above use lazy loading for showing images. In my app I used Universal Image Loader and find it extremely useful for showing a large number of bitmaps.

Loading big images with least effort

I have high quality, rich in color images in my server. I am displaying them in ListView in small ImageViews. After the user selects item, he gets fullscreen of the selected image. In this way after selecting image, the image loads quickly, as it was already loaded and I save them in cache.
The problem is that the whole List on first startup is loading pretty slow, as each item needs to be downloaded. Is there any way I could reduce the image loading in ListView? In my vision the ListView should load pretty quick, and after selection the image may load longer. I know I could optimize this by passing low quality, resized images from server to list. And after selection pass high quality image url. But this is a very big job, as I have ton of images and resizing each one of them would be a pain.
Any ideas how could I optimize this even a little?
Update: I guess my question wasn't clear enough. There is no problem with ListView, or image loading. I do not hung user at some "loading" screen, I do asynchrounsly load images, and I do simbolize that images are being loaded for each item in ListView. But with slow internet connection, the thumbnails just stay there for too long, I think the user would just quit the app... I'm looking for a way to optimize loading process. Loading just resized Images would be great, something like: 50kb for ListView and fullsize for SelectedView. I think in such way the user experience would be much better.
https://github.com/nostra13/Android-Universal-Image-Loader. Universal Image Loader is Asynchronous, uses caching and is a improves version of LazyLoading.
You can cache images in memory or disc. You can also provide custom folder to cache images. Universal Image Loader also provides you with other configuration options.
https://github.com/thest1/LazyList. you can also use lazy loading.
For performance and smooth scrolling use ViewHolder.http://developer.android.com/training/improving-layouts/smooth-scrolling.html.
http://www.youtube.com/watch?v=wDBM6wVEO70. The talk on View Holder for listview.
You can use the universal image loader. It enables you to download the images on a background thread. Basically you display the ListView with some default thumbnail and when each image is downloaded the UIL replaces the thumbnail with the real image.
That way the user will not be trapped while the images are downloading, but showing all the thumbnails will surely require downloading all the big images until you start serving small variants for the images.

How to know whether an image is displayed in ImageView?

I am trying to display some images in one ImageView to obtain the functionality of slide show.
I am registering an Animation Listener to the imageview for changing each picture.
When slide show is displaying, some of the images are not visible, but its memory is allocating.
I am converting images from URL to bitmap. After doing inSampleSize = 4, I am setting the bitmap to ImageView.
Why these images are not visible? the images with below 100 Kb are visible, but with 500kb has the problem.
Thanks..
EDITED
Actually when the application launches, the images from the URL are converted to bytes and it is stored in the DB. And when we click on the Slide show button in another activity, these bytes are converted to bitmap and showed by the ImageView.
If your images are larger than a few kB, it is best practice to use a ContentProvider rather than loading these images directly from storage. This may be your problem.
http://developer.android.com/guide/topics/providers/content-providers.html#querying
Give this a read and try the ContentResolver.openInputStream and Cursor.getBlob() method of retrieving images, and see if it works any better for you.
Hope this helps!
Sorry all,
Finally I figured out the problem.
I increase the duration of animation according to image size.
Now all images are displaying fine.

Categories

Resources