Downloading and displaying big images: possible approaches - ios

I'm developing a game where the main element of gameplay is an image of 2400x1600 pixels. So we are having some discussion about what's the best approach we could follow and confirm that we are not missing anything in order to download the image from the server and get it displayed on the device. So we thought about the different approaches and see what everyone else's thoughts are. I would really appreciate if you can list another approach you can think of. Before getting into the approaches themselves, some things that we need to take for granted:
User experience since gameplay started should be smooth. This made us get rid of one possible approach that was to implement it like Google Maps i.e. downloading tiles from the server as the user pans/zooms the map since there will be for sure some delay until the tile is finally displayed.
Images cannot be shipped within the binary file since they will be updated frequently.
All the tiles of each image weight around 6MB
So possible solutions we see so far:
Download and tiling the images in a background process/task all at once as they get updated. The big loading time here will be the first time the user launches the app. Images don't get updated together neither very frequently - one day minimum.
From the moment the user gets to the screen to select the image to play, start the process of downloading and tiling. User can select between 2 pictures only.
If user is on WiFi, use solution 1. If user is over cellular network then use solution 2.
Thanks in advance.

Use SDWebImage. It provides a ton of features for caching images, downloading in background, and much more.

The NSURLSession class in iOS 7 is well-suited for your needs. It allows for background downloads, resuming and pausing downloads, and is heavily customisable.
Now, I know this is a little vague, so here are some great references to start with :
Apple's NSURLSession Documentation
Mobile.TutsPlus NSURLSession Tutorials

Related

Recognize Logo in a full image

First, you need to know that I'm a beginner in this subject. Initially, I'm an Embedded System Developpers but I never worked with image recognition.
Let me expose my main goal:
I would like to create my own database of Logos and be able to
recognize them in a larger image. Typical application would be, for
example, to make a database of pepsi logos and coca-cola logos and
when I take a photo of a bottle of Soda, it tells me if it one of
them or an another.
So, here is my problem:
I first wanted to use the Auto ML Kit of Google. I gave him my
databases so it could train itself on it. My first attempt was to
take photos of bottle entirely and then compare. It was ok but not
too efficient. I then tried to give him only logos but after
training, it couldnt recognize anything in the whole image of a
bottle.
I think I didn't give enough images in the first case. But I'd prefer to use the second case (by giving only logo) so that the machine would search something similar in the image.
Finally, my questions:
If you've worked with ML Kit from Google, were you able to train a
model by giving images that should be recognized in a larger image?
If yes, do you have any hints to give me?
Do you know reliable software that could help me to perform tests of this kind? I thought about Azure Machine Learning Studio from
Microsoft (since I develop on Visual Studio).
In a first time, I'd like to code as few as I can just for testing. Maybe later I could try to code my own Machine Learning System but I think it's a big challenge.
I also thought that I would need to split my image in smaller image and then send each of this images into the Machine but it would be time consuming and I need a fast reaction (like < 2 seconds).
Thanks in advance for your answer. I don't need complete answer with full tutorial (Stack Overflow is not intended for that anyway ^^) but just some advices would already be good.
Have a good day!
Azure’s Custom Vision is great for this: https://www.customvision.ai
Let’s say you want to detect a pepsi logo. Upload 70 images of products with the logo on them. Use Custom Vision to draw a box around the logo for each photo. Click “train”, and you get a tensorflow model with code.
Look up any tutorial for it, it’s pretty incredible and really easy to use.

Downloading and using a large number of avatars

I'm wondering if you can help me solve more of a general, process question.
In my app when the user signs up, I create a thumbnail avatar (approx 35x35 px). I upload this to the server.
In another section of my app I display all users in a UITableView. This table is populated by a request that occurs on the view controller beforehand (so I can reduce loading screens).
This table contains approximately 100 rows. My question is, how do I load all the avatars seamlessly?
I dont want the user to tap the view and see a bunch of users, then avatars loading in randomly.
I dont want a loading screen to appear, unless its absolutely necessary (i.e. the user navigates through the app quickly).
I dont want to fire off 100 requests at once to my server.
I would like to send one request, and possibly get them back all at once. And if I did this, is there a specific format I should use? A big JSON response with base64 encoded thumbnails? :/
In addition to this, should I cache these? If so, how?
Swift 3.
Thanks!
SDWebImage is a really amazing framework that you can use to achieve this task. I've used it in every app of mine.
You can find it here: https://github.com/rs/SDWebImage
You can just put the following code in your cellForRowAtIndexPath Method
cell.imageView.sd_setImageWithURL(String.initWithURL("http://www.domain.com/path/to/image.jpg"))
The URL specified here is the link to the individual image to be shown in that particular row. This way your app can load images as the user scrolls the tableview. Given that your images are 35x35, it should be smooth and quick.
Hope this helped!
After more research based on Pratham Mehta's answer, I found a library called KingFisher:
https://github.com/onevcat/Kingfisher
This is more appropriate for my project, given SDWebImage is written in Objective-C, and my project is in Swift 3.
Check out Nuke. It's designed to support large collections of images (has built-in throttling, rate limiting of requests, etc).
And if I did this, is there a specific format I should use? A big JSON response with base64 encoded thumbnails? :/
I would suggest to avoid any premature optimizations - just download the images lazily one by one as soon as they appear on the display. Most image loading frameworks are designed to support this really well.
In addition you can prefetch the images.
If you want to do it the hard way - just zip the images and download the archive.
In addition to this, should I cache these? If so, how?
You may find this helpful.

iOS App Backend Provider

I've recently submitted my iOS Quiz app to Apple but noticed that the file size for the app is pretty big (about 150 MB). Users would need to be connected to wifi in order to download it per Apple's rules. My quiz app is set up so users are given 4 choices and shown an image and must guess the correct answer from the image shown to them. How would I minimize the file size for my app so that it isn't so large? Is there a way I can host the images on a server without losing the functionality of my app? I heard of something like Backend Services but know nothing about it. If anyone can guide me in the right direction that would be awesome, thanks!
You can check out a free back end service like Parse, it could do the trick for you, especially because you dont have a lot (besides images I guess) that'll be on the server side.
This also helped me start with using it.
Good luck :)
I'm assuming you have all the quiz data (questions and images) within your app bundle?
You can shrink it next to nothing if you move all your questions and images to a backend server and serve the questions and images (links) using simple JSON Structure.
You can build your own backend (Java/PHP/etc..) or look into using Parse.
use JPEG images whenever possible. PNGs costs more space. Do not place jpeg to xcassets, since they will be converted to PNGs. If your pictures should be transparent - it is better to use Webp or JPNG format.
You may use CloudKit to host your data in a public database. You won't need any backend knowledge to do that. This tutorial will help you understand the basics. WWDC videos covers some more, i suggest you to look at WWDC 2014, Introducing CloudKit and WWDC 2015, CloudKit Tips and Tricks.

Handling very large image files in web browsers

First post on SO; hopefully I am doing it right :-)
Have a situation where users need to upload and view very high resolution files (they need to pan, tilt, zoom, and annotate images). A single file sometimes crosses 1 GB so loading complete file on client side is not an option.
We are thinking about letting the users upload files to the server (like everyone does), then apply some encryption on server side creating multiple, relatively small low resolution images with varying sizes. We then give users thumbnails with canvas size option on the webpage for them to pick and start their work.
Lets assume a user opens low grade image with 1280 x 1028 canvas size. Image will be broken into tiles before display, and when user clicks on a title it will be like zooming in to a specific tile. Client will send request to the server asking for higher resolution image for the title. Server will send the image which will be broken into titles again for the user to click and get another higher resolution image from server and so on ... Having multiple images with varying resolution will help us break images into tiles and serve user needs ('keep zooming in' or out using tiles).
Has anyone dealt with humongous image files? Is there a preferred technical design you can suggest? How to handle areas that have been split across tiles is bothering me a lot so not sure how above approach can be modified to address this issue.
We need to plan for 100 to 200 users connected to the website simultaneously, and ours is .NET environment if it matters
Thanks!
The question is a little vague. I assume you are looking for hints, so here are a few:
I see uploading the images is a problem in the firstplace. Where I come from, upload-speeds are way slower than download speeds. (But there is litte you can do if you need your user to upload gigabytes...) Perhaps offer some more stable upload than web. FTP if you must.
Converting in smaller pieces should be no big problem. Use one of the availabe tools. Perhaps imagemagick. I see there is a .net wrapper out: https://magick.codeplex.com/
More than converting alone I think it is important not to do it everytime on the fly (you would need a realy big machine) but only once the image is uploaded. If you want to scale you can outsource this to another box in the network.
For the viewer. This is the interessting part. There are some ready to use ones. Google has one. It's called 'Maps' :). But there is a free alternative: OpenLayers from the OpenStreetmap Project: http://wiki.openstreetmap.org/wiki/OpenLayers All you have to do is naming your generated files in the right way and a litte configuration.
Even if you must for some reasons create the tiles on the fly or can't use something like OpenLayers I would try to stick to its naming scheme. Having something working to start with is never a bad idea.

Instagram MIN_TIMESTAMP not returning all images it should

I'm developing an iOS app and my idea is to display all Instagram images after a certain timestamp. I use HSInstagram to handle the API response and put all the images in a UIScrolView.
In order to do so, I do a request to the following path: users/%#/media/recent/?acces_token=MY_ACCESS_TOKEN&min_timestamp=1350000000. But the response I get is just a limited number of images, which aren't all the images after my timestamp.
I thought it was due to the limit that instagram puts on 20 images every request and thus I also tried to do the request to users/%#/media/recent/?acces_token=MY_ACCESS_TOKEN&min_timestamp=1350000000&count=-1 to avoid the limit. But in this case, the images didn't even load.
I'd appreciate any contribution. Thanks for your time!
As HSInstagram code was not prepared to implement the feature I wanted to implement, I foud an alternative called GrabKit in which you can also import your Facebook and Picasa images among others although you can disable them if you want to.
I hope this library can help you if you want to build an application that supports Instagram pictures the same way the app I'm building does. I really recommend it if you want to save thousands of lines of code as well as many hours dealing with APIs.

Resources