-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Trying to find an iOS library that can optimize PNGs during run time (most searches result in tools that optimize pngs like https://tinypng.com)
In trying to use this library I get an error trying to use optimizeData. My test code is as follows:
// Create paths
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *sourceFilePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"source.png"];
NSString *targetFilePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"target.png"];
// Save source image.
UIImage *sourceImage = [UIImage imageNamed:@"pngfile"];
NSData *sourceImageData = UIImagePNGRepresentation(sourceImage);
[sourceImageData writeToFile:sourceFilePath atomically:YES];
self.originalImage.image = [UIImage imageWithData:sourceImageData];
NSLog(@"Source Path: %@", sourceFilePath);
// Optimize image
//NSData *optimizedImageData = [sourceImageData optimizedData];
NSData *optimizedImageData = [sourceImage optimizedData];
UIImage *optimizedImage = [UIImage imageWithData:optimizedImageData];
// Save target image
UIImage *targetImage = optimizedImage;
NSData *targetImageData = UIImagePNGRepresentation(targetImage);
[targetImageData writeToFile:targetFilePath atomically:YES];
self.optimizedImage.image = [UIImage imageWithData:targetImageData];
NSLog(@"Target Path: %@", targetFilePath);
If anyone finds a good solution for optimizing pngs at run time let me know! PS - I can't save as JPG since transparency is needed.
Metadata
Metadata
Assignees
Labels
No labels