【问题标题】:pngcrush caught libping error, but only when building for devicepngcrush 捕获到 libping 错误,但仅在为设备构建时
【发布时间】:2013-06-09 03:47:06
【问题描述】:

我的 iPhone 应用项目中有一些 png 文件。当我为模拟器构建时,它们工作正常。但是当我为设备构建时,突然每个单独的 png 文件都会生成可怕的“在读取 such-and-such.png pngcrush 时捕获 libpng 错误:...找不到文件:...”

正如我所说,一切都在模拟器上构建和运行得很好。只有当我更改为设备构建的方案时才会出现错误。

我尝试清理和重建。

我尝试手动删除 Products 目录。

我尝试重新启动我的系统。

我尝试在不同的项目中使用这些文件(那里的结果相同)。

我发现唯一可行的方法是打开文件并重新保存它们。但是,这不是最佳解决方案,因为我有数百个 PNG 文件都遇到了这个问题。我宁愿了解问题是什么,以便我可以直接解决它。

有什么想法吗?

【问题讨论】:

    标签: iphone ios xcode libpng pngcrush


    【解决方案1】:

    通过编写一个又快又脏的递归文件重新保存程序来解决这个问题。我已经验证,只需对我的项目目录运行它就可以修复我看到的 459 错误。这是相关的代码,以防它帮助任何人。

    - (IBAction) btnGo_Pressed:(id) sender {
        // The path to search is specified by the user
        NSString *path = self.txtPathToSearch.stringValue;
    
        // Recursively find all files within it
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSArray *subpaths = [fileManager subpathsOfDirectoryAtPath:path error:nil];
    
        // Look for pngs
        int totalImagesResaved = 0;
        for (int j=0; j<[subpaths count]; j++) {
    
            NSString *fullPath = [path stringByAppendingPathComponent:[subpaths objectAtIndex:j]];
    
            // See if this path ends with a ".png"
            if ([fullPath compare:@".png" options:NSCaseInsensitiveSearch range:NSMakeRange([fullPath length] - 4, 4)] == NSOrderedSame) {
    
                // Got one. Now resave it as a png
                NSImage *image = [[NSImage alloc] initWithContentsOfFile:fullPath];
                [self saveImage:image asPngWithPath:fullPath];
                totalImagesResaved++;
            }
        }
    
        // Status report
        NSAlert *alert = [NSAlert alertWithMessageText:@"Done" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"Encountened %li paths. Resaved %i .pngs.", (unsigned long)[subpaths count], totalImagesResaved];
        [alert runModal];
    }
    
    - (void) saveImage:(NSImage *) image asPngWithPath:(NSString *) path
    {
        // Cache the reduced image
        NSData *imageData = [image TIFFRepresentation];
        NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData];
        imageData = [imageRep representationUsingType:NSPNGFileType properties:nil];
        [imageData writeToFile:path atomically:YES];
    }
    

    【讨论】:

      【解决方案2】:

      听起来好像你有用 Apple 的流氓“pngcrush”Xcode 程序重新压缩的 PNG 文件,该程序写入的文件不是有效的 PNG。在文件开头(从第 12 个字节开始)附近查找字符串“CgBI”,其中“IHDR”应该是。有一些应用程序(包括 Apple 版本的“pngcrush”)可以解决这个问题。

      【讨论】:

      • 感谢您的回复。您是说 Apple 将坏版本的 pngcrush 与特定版本的 XCode 捆绑在一起?我从来没有故意自己安装过。
      • 他们为真正的 pngcrush 添加了功能,并使其成为 Xcode SDK 的一部分。这发生在几年前,据我所知,到 2014 年仍然如此。
      • 那我想我没听懂你的最后一句话。您说“有些应用程序(包括 Apple 版本的“pngcrush”)可以解决问题。”但是你不是说 Apple 版本的 pngcrush 是导致问题的原因吗?
      • 是的。 Apple 修改了我的“pngcrush”程序以添加 -iphone 和 -revert-iphone-optimizations 选项。如果您使用“-iphone”,由于各种原因,您最终会得到一个不是 PNG 的文件。如果您在该文件上使用“-revert-iphone-optimizations”,您将返回一个有效的 PNG 文件,尽管图像透明部分的颜色会丢失。
      • 有趣。感谢背景!
      猜你喜欢
      • 2020-07-15
      • 2014-09-03
      • 2021-04-27
      • 2020-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多