How to use a big bunch of photos in iOS app - ios

I'm creating an iOS app where I need to use many photos(in big resolution). There're almost 400 photos. I want to use them to show in UIImageView on the different pages.
But it's a big bunch of data. So I'm afraid about efficient(not so much) and size of the app itself. What's the best way to use these photos in my iOS app? Does it make sense to create New Image Set and create 1x,2x and 3x photos for each photo or do I have to use other features I don't now about?
UPD1:
The app is about sights. From the tableview user can chose any sight and will be shown screen with 1-3 photos( in CollectionView if there's more than 1 photo) and some text. All data(except photos) I'm getting from sqlite db using CoreData.
The photos are shown on the screen have width equal to screen width (the height 25:38 from width). Width is bigger:)
I want to use big resolution photos because I want show full-size
photos by tap.
Each photo can be 2000px or more on the biggest
side.
The app is an offline app so I want to store photos in the
app. I now just about image assets. But are there other ways to
store photos?
I have an idea to store them in high-resolution and resize to any device(3x, 2x, 1x) to display on the screen. And load high-resolution version of a photo just when user taps on it to show the photo on the full screen.

You cannot load all the photos from the app - this is btw. not possible because of memory issues during loading images.
You should at the beginning think about presenting photos and photos itself.
Do you really need to show photos in big resolution?
What big resolution means? Is that 1024x1024 or native resolution or what?
From where these photos are loaded? App includes it or you'll load them from system library? I see you're writing about image assets, probably you want to keep them in the app.
Do you need to show this images in constant almost 0 time? Maybe keeping it on the backend and fetching and cache when necessary will be better approach. With this you can decrease size of the app.
You can keep in assets only the biggest one - the #3x and resize it on devices that need this in runtime before displaying it.
To keep photos in device's memory you can use NSCache - Apple's Documentation and let system managing the photos. You'll load this and cache in the instance of NSCache and every time you want to access it and get photo you have to check if there is photo or nil and if nil you have to re-load it again from the disk. This will somehow keep your device to not get memory warnings and will automatically managing photos.
Another important thing to think is to how you plan to show the photos. Is is possible to show only 1 at a time or there is more to show? Do you want to present thumbnails of them and after user select some photo show it in the big resolution? Using thumbnails will have less memory footprint.
Update 1:
UPD1: The app is about sights. From the tableview user can chose any places and will be shown screen with 1-3 photos( in CollectionView if there's more than 1 photo) and some text. All data(except photos) I'm getting from sqlite db using CoreData.
The app is an offline app so I want to store photos in the app. I now just about image assets. But are there other ways to store photos?
You don't need assets catalog for this. Just keep it in some directory in the project and load them from /Documents directory when necessary. IMO this will be the best possible approach to store and use locally. Keeping them in the assets will cause that there will be #1x and #2x empty in xcassets file. And keeping them directly in project will be easier to maintain I think.
I want to use big resolution photos because I want show full-size photos by tap.
Each photo can be 2000px or more on the biggest side.
I have an idea to store them in high-resolution and resize to any device(3x, 2x, 1x) to display on the screen. And load high-resolution when user taps on the photo to show photo on the full screen.
Keeping such big photos in the app is poor idea, the app will be big. Even if one photo will be 1mb size which I think is not possible and there are 400 photos the app will be fat.
You should consider keeping them online, really.
You also know all the images in the app so you can create thumbnails in real time and cache them in /Cache directory for later use. The same with big photos for specified device screen resolution. Before displaying resize it and save in /Cache directory for future next time use.

Related

Prevent manual screenshot in IOS Objective-C

On iOS, my requirement is disallow user to take manual screenshot from my application, either disallow or blur the captured screenshot. How?
The only solution is to simulate the iOS controls you have in your View using DRM'ed videos.
For each widget you need to create a video subclass that renders the widget, and apply DRM to the video.
You can try to do it yourself, or use a commercial solution such as the following:
https://screenshieldkit.com
It is possible but I don't recommend it because of the room for error. It was easier to do in the past, in iOS13 you will have to do it like this:
You will have to ask for the user's permission to read and edit their photo library, then you have a listener which is checking the number of photos in their library while they are using your app, if that number changes, they have just taken a screenshot (unless you allow other things in your app like tap and hold to save image, etc). When this happens, read said photo and apply a blur, then delete the photo from their library and save the blurred photos.
Warning: There are times where a user may get a photo while using your app that is not a screenshot (e.g. they received an airdrop) and you will now be tampering with their photos, which is very bad. To prevent this you may need to use key value pixel encoding on your screen at all times, for example the first 3 pixels of the screen are 3 very specific RGB values, that way if a new photo is detected and the first 3 pixels are those exact RGB values you know it's a screenshot of your app and not just another photo that was somehow saved while the user was using the app.
There isn't any regular solution to your problem!
You can do some tricks such as if you force the user to have their finger on the screen for the image to show then I don't think they can create screenshots. Because as soon as you press the home+lock keys to actually take the screenshot, the screen seems to behave as if there are no fingers touching it.
BUT what if the user takes a screenshot by AssistiveTouch?!
OR what do you want to do if user records screen and taking screenshot from the video?
I think it's better to change your strategy for example notify the owner of picture for taking screen shot by another one (like SnappChat)!

Accessing Images from gallery and showing in iOS app gallery

I have around 1000 ’s of Images, I want show them in my app. What are the possibilities to do that..
The ideas which I’m thinking
1.Saving all images in phone gallery. accessing images form gallery… but It seems not possible as each iOS app has its own sandbox.
2.Saving in my bundle which will increase the memory size.
In android there is a control called “ViewPager”, how can i achieve the same control in iOS ….
Tried scrollview with paging technique but crashes due to memory ....
Please guide me…..
I dont think you can show images from the gallery directly to your application . But you can store it into document directly , for that you have to first pick images from the gallery . you can refer
How to load photos from photo gallery and store it into application project?
And next time when you start application you can load images from the document directory so you dont need to go to the gallery again .

Displaying multiple images causes massive memory usage

I have an app that allows a user to go into their gallery and select photos from their photo library to add to the app, it is displayed in a tableview
This is then added to an array which after UIImagePickerController fetches the image, reloads the collection view with the new images.
My problem is that this uses large amounts of memory. I need a way to display the photos added exactly like the native photos app on the iPhone.
I've looked in lazy loading but I have no idea where to begin.
Could someone please tell how I would go about displaying images in a UICollectionView with lazy loading, or at least reducing the amount of memory used.
The app is generally at normal use using around 10mb of memory. This increases to 50mb+ when displaying a multitude of images in the collectionView.
Thanks.
Holding high-resolution images into an array will generally be problematic. Also, using the full resolution images for thumbnail sized image views in collection view is an extravagant use of memory.
So, when the user selects an image, capture a reference to that asset's URL. Then, as images are required by cellForItemAtIndexPath, retrieve the image, resize it to thumbnail dimensions (e.g. you could use something like this) and use that in your cell's image view.
If you want to be elegant about it, implement a NSCache in which you'll cache previously resized images, but make sure you have reasonable retention rules and have that purge itself upon memory pressure. That way, cellForItemAtIndexPath can see if the image exists in its cache, and if so, use that, otherwise go back to the assets library and resize that image. But by using cache, you can speed up the process of scrolling back through images that were previously resized.
But the key is to avoid holding high resolution images in memory. And if you're going to hold even the thumbnails in memory, you might want to capture that in something like a NSCache rather than an array.

iOS: Best approach for image gallery [Image Caching]

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

How do I allow cropping and positioning of photos in ruby on rails?

So on users profiles I will have banner space where they can upload a photo to. I want the space inside the banner to be filled with the photo. Not every user will be good with creating banners in photoshop etc so I'd like to give them some control on how their photo will look in the banner by allowing them to resize it proportionally and position it left, right, up or down until the photo is showing the way they want it to in the banner.
I'd like some limits however in order to stop users from uploading very small photos that won't look good inside the banner. I've checked out google+ which seems to allow this so a perfect example of what I'm looking to do is what facebook do with their timeline banner photo upload option.
I currently use carrierwave for all photo processing in my app.
Any advice/solutions to get me started will be much appreciated.
Kind regards
You will need some kind of client editor for the banner. I mostly used the Jquery UI Plugin (JqueryUI), which helps you with some nice methods. You can easily add some draggable, resize or position functionality.
After the user finished the banner, you can upload the whole banner to the backend. For the storage and configuration of photos in rails, I recommend to use the gem 'paperclip' (Paperclip). You can set a minimum or maximum size in paperclip when pictures are uploaded.

Resources