2011-08-18 27 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乘法,以便所有圖像能夠非常快速地由硬件圖形處理器渲染。

相關問題