Question

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.

Was it helpful?

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.

OTHER TIPS

You could read the raw jpeg data from the ALAssetsLibrary like this:

ALAssetRepresentation *rep = [self defaultRepresentation];
uint8_t *buffer = (uint8_t *) malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];

Then you could make use of libjpeg and decode only the rect that you need (rounded up by 8 pixels). See the source of the jpegtran utility for reference.

There are some threads on compiling libjpeg for iOS on stackoverflow.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top