2011-08-18 46 views
1

我正在使用Objective Zip库来解压iPhone中的文件。目标 - 邮编仅适用于文本文件?

所有工作正常,除了文本文件没有问题没有问题没有压缩,文件是正确的。但与压缩PNG文件都损坏。文件的大小都与原始文件相同,但全部损坏。

这是代码:

-(void)installPackageFromZipFile:(NSString *)zipFile 
{ 
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDir = [documentPaths objectAtIndex:0]; 

    ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:zipFile mode:ZipFileModeUnzip]; 
    packageRegisterController *pckReg = [[packageRegisterController alloc] init]; 

    [unzipFile goToFirstFileInZip]; 

    NSArray *infos= [unzipFile listFileInZipInfos]; 

    for (FileInZipInfo *info in infos) 
    { 
     NSLog([NSString stringWithFormat:@"File Found in Zip File- %@ Size:%d", info.name, info.length]); 


     ZipReadStream *read = [unzipFile readCurrentFileInZip]; 

     if (![pckReg detectIfFileExists:[documentsDir stringByAppendingPathComponent:info.name]]) 
     { 

      NSMutableData *data = [[NSMutableData alloc] initWithLength:info.length]; 

      int bytesRead = [read readDataWithBuffer:data]; 

      [data writeToFile:[documentsDir stringByAppendingPathComponent:info.name] atomically:NO]; 

      [read finishedReading]; 


      [data release]; 

      if ([[NSString stringWithFormat:@"%@",info.name] isEqualToString:@"TEMAMANIFEST.xml"]) 
      { 
       if([self parseManifest:[documentsDir stringByAppendingPathComponent:info.name]]) 
        if ([pckReg validateManifestId:self.temaToInstall.idManifest]) 
         [self installManifest]; 

      } 

     } 
     [unzipFile goToNextFileInZip]; 
    } 

    [unzipFile close]; 
    [unzipFile release]; 
} 

此功能解压缩具有良好的尺寸和文本文件中的所有文件都OK,但不是PNG文件。

有人可以帮助我吗?

+0

您是否尝试解压缩另一个盒子上的zip文件,并确保其压缩正确? –

+0

剔除我在这个问题中的答案: - http://stackoverflow.com/questions/2161327/creating-zip-files-in-objectivec-for-iphone – nlg

回答

1

您是试图在iPhone应用程序中查看图像,还是将它们压缩,在Mac上解压缩并尝试在其中查看它们?

当为iPhone构建时,PNG是“优化的”,因此在未被“未优化”的情况下无法在Mac上查看。

当PNG图像被复制到它们通过pngcrush工具,它需要的图像的alpha通道值和与所述其他色通道,红色,蓝色和绿色premultiplies它发送一个iPhone应用程序包。其结果是在Mac上无法看到的图像,但在iPhone上的快速,易于渲染的图像。

这样做是因为iPhone的图形处理器不会在硬件中进行alpha乘法,而是在软件中进行,这会使其变慢。 pngcrush实用程序会执行构建过程中所需的所有alpha乘法,以便所有图像能够非常快速地由硬件图形处理器渲染。

相关问题