Does the iPhone compress images saved within my app's documents directory?

Posted by Jane Sales on Stack Overflow See other posts from Stack Overflow or by Jane Sales
Published on 2010-03-18T11:22:22Z Indexed on 2010/03/18 12:11 UTC
Read the original article Hit count: 296

Filed under:

We are caching images downloaded from our server. We write them to our local storage like this:

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0] ; 
 NSString* folder = [[documentsDirectory stringByAppendingPathComponent:@"flook.images"] retain];
        NSString* fileName = [folder stringByAppendingFormat:@"/%@", aBaseFilename];

 BOOL writeSuccess = [anImageData writeToFile:fileName atomically:NO];

The downloaded images are always the expected size, around 45-85KB.

Later, we read images from our cache like this:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0] ; 
 NSString* folder = [[documentsDirectory stringByAppendingPathComponent:@"flook.images"] retain];
        NSString* fileName = [folder stringByAppendingFormat:@"/%@", aBaseFilename];

 image = [UIImage imageWithContentsOfFile:fileName];

Occasionally, the images returned from this cache read are much smaller because they are much more compressed - around 5-10KB. Has the OS done this to us?

© Stack Overflow or respective owner

Related posts about iphone