I've been using HJCache to do asynch image loading and caching. It works great, but I have use case where I can't seem to get HJCache to handle.
I have an images loaded in a table view, and the same images appears bigger when you select the corresponding tableviewcell. HJCache does a great job of caching the image so it doesn't have to reload it after getting it once. However, I would like to resize the image (and do some cropping, etc) in the tableview thumbnail. The problem is, that it's a very expensive task to do and it ends up lagging the scrolling of the tableview if it's done in the drawRect of the cell.
I would like to cache the "modified" image along with the original so that the image processing only has to happen once. How do i get an instance of the already cached UIImage, apply the processing, and then add that one to the cache as well (with a different oid). I only seem to be able to cache an image by giving a URL.
Thank you,
Matt
Related
Can anybody tell me how to load or set images with high resolutions in UIScrollVIew .
I am getting memory warning and app is getting crashed without any stack trace.
Thank you in advanced.
I was also working on an app which had UIScrollView and had to request for High Resolution Images. The thing is, you should first check the size of the images being downloaded. Lets say, if the image size is more than 10MB, then it would be difficult for your app to survive with such a heavy load.
You can consider the following methodologies.
1.Download your images and compress them.
2.At a particular instance of time, there is no need to populate your Scroll Views array with all the images at once, instead try to have only three images,i.e
1.The current one which is being shown.
2.The previous one.
3.and the image next to the current one.
You can also take help from the link
http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content
You should use the concept of lazy loading. As you said you used UIScrollView that's mean you have lot's of images and I guess you show them one by one or two or three at a time. Load only that images which are visible to the user. One more thing you have to maintain that is when user swipe to next image or next branch of images that's mean next image(s) that's are going to visible to the user. At that time before load the new images release all the previously loaded images from memory. I hope it'll solve your problem.
If you are trying to create multiple UIImageView of high resolution image inside UIScrollView, then it will create memory warning and application will crash.
I will suggest you to try reusable UIImageView , like create 3 UIImageView and replace images in it.
Try circular scrollview.link or UICollectionView
In my app, I display images with scrollview. I avoid memory issue by adding view as user scroll through. Scrolling seems fine but it stop in split second when new image is loaded on next/pervious view. I tried to load image on NSThread but no performance was improved.
I use [UIImage imageWithData:] to load image. I wonder if there is a way to load an image more efficient way. It would be appreciated for any comments regard this issue.
I think the best way is to keep three pictures at once in memory: the picture on the current screen, the picture on the next screen and the picture on the previous screen. By doing this you can scroll smoothly. You can use your imageWithData method with this procedure.
It gets even simpler if you use imageNamed instead, because this method caches the pictures if it has enough memory. So you just have to load the current picture and the next picture by just calling
[UIImage imageNamed:#"nextPic"];
By executing this, it loads the picture into the cache but does not display it. The next time you have to display the picture it is already in memory.
I am trying to lazily load a dynamic thumbnail view.
I have to put images in thumbnail view one by one and until images are not available I have to display temporary image like placeholder. Any guidelines please?
See the accepted answer in this thread. You wouldn't need the last-in first-out stack, but it shows how to load images asynchronously using grand central dispatch, which is quite straightforward. You don't need to think about complicated thread management. :)
You could go about like this -
Create a UIImageView with a default placeholder image.
Fetch your image in a background thread. You want to do it like this
because, fetching image in the main UI thread blocks it till the
image is fetched, which severely hampers UI responsiveness. There
are several libraries available which do this for you. They even
cache the images. SDWebImage is great!
See if you get a valid HTTP 200 response back i.e. a valid image. If yes, then replace the new image with placeholder image. Else let the placeholder image be.
Hope this helps...
I have a table view with all cells having the UITableViewCellStyleSubtitle,
the images of all the cells are got from the server.
However, those images are not changed frequently.
Someone can show me how to improve the user experience? Each time, user scroll down the table, it seems that it goes online to check and download images again.
Or at least, show me some options that are available to achieve the goal.
Thanks,
The Three20 library has an ImageView subclass that accepts a URL to your remote image and uses the excellent TTURLRequest/Caching mechanism to fetch images. It maintains an in-memory and on-disk cache and will only download images if they are not cached or have expired. You can configure the default cache-expiration time or use a value from your HTTP response. If you use the TTTableViewController subclass and the appropriate TTTableItem subclass, you will get the appropriate image downloading behavior for free. However, it is not necessary to use every three component to do what you need. If you're integrating into existing code, you could create your own UITableViewCell subclass that uses a TTImageView instead of the standard UIImageView. Then, in your cell configuration methods, you can set a default placeholder image and a URL to load and it will pretty much take care of the rest. As a performance optimization, you should also implement the UIScrollView delegate methods in your tableview controller to suspend the TTURLRequestQueue during scrolling (take a look at the TTTableViewController to see how this is done).
You could try one of the following
Create an dictionary and cache all the fetched images in it using the image name as the key
Cache and reuse the entire UITableView cells in tableView:cellForRowAtIndexPath:
If it is just one image repeating load it one outside tableView:cellForRowAtIndexPath:
You write that the images change on a monthly basis - you could save the images to disk as they are used and just either check if the images have changed on the back burner or at a given daily interval redownload the images. Brian Chapados reply seems interesting .
Depending on your code there is probably a ton of other ways to improve image loading. Hope that helps...
I have some 50 custom cells in my UITableView. I want to display an image and a label in the cells where I get the images from URLs.
I want to do a lazy load of images so the UI does not freeze up while the images are being loaded. I tried getting the images in separate threads but I have to load each image every time a cell becomes visible again (Otherwise reuse of cells shows old images)
Apps like Facebook load images only for cells currently visible and once the images are loaded, they are not loaded again. Can someone please tell me how to duplicate this behavior.
Thanks.
Edit
Trying to cache images in an NSMutableDictionary object creates problems when the user scrolls fast. I am getting images only when scrolling completely stops and clearing out the cache on memory warning. But the app invariably gets a memory warning (due to size of images being cached) and clears the cache before reloading. If scrolling is very fast, it crashes.
Any other suggestions are welcome
Loading the images on a background thread is still a good idea. If you didn't want to reload them each time, I'd suggest setting up an NSMutableDictionary and storing the images in there. You could use some unique identifier, like the row ID or even the name of the image, as the key for each image.
When loading a cell, you'd send an objectForKey: message to the NSMutableDictionary to retrieve the image for that particular cell (based on your unique key for it). If it returns nil, that means that the image is missing from the cache and you need your background image loading thread to go retrieve it. Otherwise, you will get back the appropriate image for your table cell to display. On a memory warning, you could clear out this cache of images with no adverse effects (aside from forcing them to be reloaded again on demand).
I have just successfully tackled the same problem by using a custom NSOperation to load the images in a queing fasion and stored them into a static NSMutableDictionary as a cache. Below is a link to the basis of the code I used to solve the problem.
Loading remote images for UITableViewCell
Best to read all the threads in the forum to help you understand what's actually going on.
lostInTransit,
I am having a similar problem and while exploring the many different possible solutions I found this blog post:
davidgolightly.blogspot.com/2009/02/asynchronous-image-caching-with-iphone.html
I would also suggest that you download the URLCache sample from the apple developer website:
developer.apple.com/iphone/prerelease/library/samplecode/URLCache/
And here is another post on the problem:
www.markj.net/iphone-asynchronous-table-image/
I'd love you to share your findings as well.
Lazy loading is like synchronous type request.. means wait for respond
ego image button is solution for that..
ego image button is asynchronous type request..don't wait for respond..just display data at a time....
you can download folder from github....
add to your project...
in xib..at image view ,change class to ego image button...
make object of it in m file...
you can use.....
For those who are interested, and are lazy like me, I would like to suggest an open source (MIT license) implementation of lazy/cached network of UIImageView images: SDWebImage
UITableView with image caching and resizing/setting in background thread:
http://blog.slaunchaman.com/2011/08/12/gcd-example-updated-now-with-more-speed/
This is Tutorial about NSOperation with example that show how to Lazy load images in UITableViewCell