Search code examples
iosios6alassetslibraryalasset

How can I load a section of an image in iOS, without loading the entire contents in to memory?


I am using a table view with varying cell sizes which hold an image. Since it's varying size, I use the ALAsset fullScreenImage at times to get higher resolution than the cached thumbnails. However, since it is loading a rather large image from disk, there is noticeable delay (while the thumbnails load nearly instantaneously).

Is there a way to load a specific resolution image, or a part of an image (such as the left half or right half of it) from disk? I'd think the entire thing would need to be loaded into memory since it's usually a compressed jpeg, but I thought I would ask in case there's something I've not considered.


Solution

  • That is possible for some image formats, but not really for jpeg or png files. You'd also have to write it yourself since there is no API for this in iOS, however, if your only concern is the short delay, you can wrap the loading into an async GCD queue and use the thumbnail while the higher res image is loading.