Morrowless
Morrowless

Reputation: 6958

iOS-optimized png with transparency

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

Answers (2)

Thorsten S.
Thorsten S.

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

manikal
manikal

Reputation: 973

try setting the UIImageView's backgroundColor property to [UIColor clearColor];

Upvotes: 0

Related Questions