Reputation: 6958
I'm using this excellent OptimizedPNG for downloaded (not Xcode bundled) images, but it appears to turn transparent pixels black. Is there a similar utility (optimized using CgBI format) that works for PNGs that include transparency?
example usage as requested:
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:IMAGE_URL]]];
NSData *data = [image optimizedData];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"optimized-image.png"];
[[NSFileManager defaultManager] createFileAtPath:filePath contents:data attributes:nil];
Upvotes: 1
Views: 995
Reputation: 4274
Easy answer: Forget "optimized PNGs".
http://imageoptim.com/tweetbot.html
http://www.cocoanetics.com/2011/10/avoiding-image-decompression-sickness/
I am using PNGOUT to compress the images as good as possible and I can verify that there is no difference in speed.
Upvotes: 1
Reputation: 973
try setting the UIImageView's backgroundColor property to [UIColor clearColor];
Upvotes: 0