这是indexloc提供的服务,不要输入任何密码
Skip to content

<Error>: ImageIO: PNG [00][00][00][00]: invalid chunk type #1

@VentureNguyen

Description

@VentureNguyen

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions