I have to implement an Image Gallery for the iPhone iOS. Pictures are loaded from the web based on an XML document which contains the URLs of the pictures. My question is - what is the best approach for implementing an Image Gallery Overview of all pictures of a certain gallery? (where all pictures are presented to the user at once, like in a GridView. This question focuses on performance issues because one gallery can have more than 100 photos - each of them has a size of 100KB or more).
I already tried to implement a simple View which consists of multiple UIImageViews (rows and cols) where the images are loaded asynchronously. But the App crashes with low memory warnings, so I have to load the pictures on demand and not all at once.
What would be the best way to implement such a Gallery Overview? Using an UITableView with 3 pictures for each cell for instance? Or is it better to use a paged UIScrollView where the user is able to switch between pages where each page presents 12 pictures or so?
The main problem is the caching of the images. Would be glad for some hints.
You can cache images regardless on which solution you do, to cache the images you can either implement your own caching mechanism or use one already mad ( i opt for the second choice) i normally use ASIHTTPRequest, more specifically i use ASIDownloadCache check their documentation but its very easy to use
Related
I am trying to code a "webpage selector" on my app, using a fancy carousel to display the webpages thumbnails.
However, I don't want to display the webpages thumbnails as webViews on my carousel because I can get quite a large number (20-30) of webpages at the same time and loading all of those can cause a lot of lag.
So, I decided to use screenshots of the webpages and use those images to populate my carousel instead, making the carousel animation much smoother.
Here is my question:
I would like to know if there is any way to take a screenshot of the webpage (without showing it on the app screen) and save the image into a list that I can use to populate the carousel.
I am aware of this question but is quite an old post, so I was wondering if there is another way to do it. Also, I tried to implement the suggested solution, but it did not work.
You can create a WKWebView that is behind your view controller (and thus invisible) and constrained to the size that you want. Once the page finishes loading take a snapshot by using drawHierarchy(in:afterScreenUpdates:) inside of a UIGraphicsImageRender and save the resulting image as your thumbnail.
I'm attempting to create an Instagram styled app and cannot figure out a way to display media in a UITableView the way they do (either video or image in a single view). I know it most likely is a custom implementation of UIWebView or something of the sort, however I have no idea where to even begin writing a subclass like that. Things I've already tried include:
Using a UIWebView (massive memory leak, even when adding/removing the views programmatically).
Adding either UIImageView or UIWebView depending on whether or not it was a video or image (again had a memory leak)
Searching the internet for a possible way to do this
If anyone could help me out that would be awesome! FYI the media I am using is grabbed straight from my server, there is no data being gathered from a popular source such as YouTube, Flickr, etc.
i think they use UICollectionview as it allows for better customization of a table.
In terms of images and videos, use UIImageView to display all your images and MPMoviePlayerController to play videos.
Hi i am pretty new to IOS so pardon for silly questions . I am working on an app which loads large images in a tableview. Images to be loaded are of large size (>5MB) so i am trying to resize the image into thumbnails ,cache it and the load it asynchronously to table view. i found many ways and discussions for doing the same for network images (SDWebImages etc.) but i couldn't get anything for doing the same with local images (camera/photo library). Can any one tell me how to implement it?
You need to implement lazy loading of image along with asynchronous loading of images.
https://developer.apple.com/library/ios/samplecode/LazyTableImages/Introduction/Intro.html
https://github.com/rs/SDWebImage
http://iphonedevelopment.blogspot.in/2010/05/downloading-images-for-table-without.html
Say I load a webpage with an image on it. Is there a way to reuse this loaded image within a UIImageView without reloading the image from a url?
If the image is cached by URL loading system, it will come from the cache when you try to load it.
Sorry I can't give a large explanation as im on y phone but I feel like what your looking for is 'core data store' there are several examples of how to use this framework, but it's quite complicated and has a large learning curve with ios development.
Also you say 'a' uiwebview. Does that mean that the URL your accessing to show within your uiwebview is static? If so, just copy and save the image and store the image in your project for future reference.
Or are you allowing the user to keep swapping through links in the uiwebview and store all those images that popup on the web page?
Sorry I'm just unclear with the question... Please no down votes :)
Imagine you use a web service that delivers images via an API. Every image has an UID and you have a Core Data entity Image with attributes uid (int) and image (transformable).
Now a gallery of your app needs to show many images (the UIDs are known). You don't know which of the images have been downloaded and stored before. How can you lazily download images with core data in the background, so that the view may show an UIActivityIndicator during loading and automatically shows the image as soon as it is stored locally (e.g. by using the NSFetchedResultsControllerDelegate protocol)?
Is it useful to subclass UIImageView for that purpose?
Yes, you can use Core Data for this, but be forewarned that there is a performance hit when you use Core Data to store images. It's negligible if you're dealing with small (e.g. thumbnail) images, but for very large images, the performance hit is observable. For large images, I'd store the images in Documents folder (or, better, a subfolder), and use Core Data to keep track of what images have been downloaded, their filenames, etc. But if the images are smaller, keeping everything right there in Core Data is cleaner.
I probably would not want to use a subclassed UIImageView for this purpose, because you might want to decouple the presentation layer (the image view) from the caching of images. Also, for sophisticated user interfaces, UIImageView objects may be discarded or reused as the user scrolls through a big collection of images, so you might not want a hard link between the UIImageView and your caching logic. Also, depending upon your user interface, sometimes the images can dictate something broader than the UIImageView (e.g., if you're using a tableview, you might want to adjust the cell height based upon the image as it's downloaded). The particulars of the implementation of what the UI might do depend upon where the image is being used (a UITableView, a UIScrollView that is showing a grid of images, etc.).
So, bottom line, for simple user interfaces, perhaps you could subclass a UIImageView but I'd generally advise to have some custom image caching object that does the lazy loading with some delegate protocol to tell the UI when the image load is complete.
I wouldn't use Core Data to store images, but I'd store them on disk. I was trying to find in the documentation where Apple themselves warn against storing images larger than 100k or so in Core Data since you'd run into a performance issue.
However, I found this article that talks about Core Data Image Caching that may be of use.
Also, here's another Stack Overflow post with a good answer that tells you when to store images in a database and when to just use references to disk storage.
If you don't absolutely need Core Data, then may I recommend using MWPhotoBrowser?
https://github.com/mwaterfall/MWPhotoBrowser
It essential generates a gallery view controller for you which you can push onto your navigation controller. The gallery view controller has scrollable images with pinch zoom, pan, everything, even emailing the photo to someone.
It also does the lazy loading of the image with the activity indicator.
Short answer: everything you wanted to do without reinventing the wheel.