Reputation: 39
I'm working with Objective Zip library in order to unzip files in iPhone.
All works fine excepts, that with text files there are not problem are uncompressed without problem and the file is correct. But with compressed png files are all corrupted. The sizes of the files are all equal to original file but are all corrupted.
This is the code:
-(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];
}
This function decompress all files with good sizes and text files are ok, but not png.
Could someone help me?
Upvotes: 1
Views: 922
Reputation: 58448
Are you trying to view the images within the iPhone app, or are you zipping them, unzipping them on a Mac and trying to view them there?
PNGs are 'optimised' when built for iPhone and as a result aren't viewable on a mac without being 'unoptimised'.
When PNGs are copied to an iPhone app bundle they are sent through the pngcrush
utility which takes the alpha channel value of the image and premultiplies it with the other colour channels, Red, Blue, and Green. The result is an un-viewable image on a Mac, but a speedy, easily renderable image on an iPhone.
This is done because the iPhone's graphics processor does not do alpha multiplying in hardware, but does it in software, which makes it slow. The pngcrush
utility does all the alpha multiplying required during the build process so that all the images can be rendered by the hardware graphics processor really quickly.
Upvotes: 1