How to store a very large image on iPhone / iPad

What is the best way to store a very large image for an iOS application? I want the application to be able to view images, which can be hundreds of megabytes, possibly up to a gigabyte like jpeg. I need to be able to save an image and extract selected areas for display.

Currently, images are cut into 512x512 pixel tiles and saved as jpeg files in a directory tree with tens of thousands of fragments (this is actually a pyramid of images, including thumbnails).

Ignoring the issue of displaying an image, I’m interested in the most efficient and manageable way to store this data on the device: files, as they currently are, in the sqlite database or something else?

The second part of the question. Is there a limit on the amount of data that the application can store, or whether the application can store data to the storage limit of the device. I ask here about the data that the application imports after installing it.

+3
source share
3 answers

The solution to this is to pre-split the huge image so that fragments can be quickly extracted from the file system as needed. One problem with very large images is that most solutions require the entire image to be displayed in context, consuming a huge amount of memory. On a system like iOS, where memory is limited, the way to solve this problem is to use a library like libjeg or libjpegturbo to render the image at a time, then save the pixels in a raw file. The disadvantage of this is that when you need one tile, you need to jump across the entire file system, finding each row of tiles. Thus, the best solution is not only gradual scanning, but also gradual alternation. You can use mmap to map the file to the desired area, so you can really minimize memory consumption. However, you can split a single buffer queue on iOS, so the application crashes or even the whole system!

If you are interested in how to implement the above solution, there is a free project on github - PhotoScrollerNetwork - this does all of the above.

+2
source

Apple Sample: PhotoScroller

+1
source

How about dividing into parts. Then it can be assembled according to your application.

-1
source

Source: https://habr.com/ru/post/1391470/


All Articles