我需要将以编程方式捕获的屏幕截图保存到文件夹中并压缩它。那可能吗?有人帮忙
答案 0 :(得分:2)
第一步 - 创建屏幕截图:How to take a screenshot programmatically
第二 - 保存它:How to save UIImage to file with NSFileManager?
第三 - 拉链。您可以使用zlib wrapper objective-zip
EDITED:这是来自objective-zip嵌入式示例的一些代码:
ZipFile *zipFile= [[ZipFile alloc] initWithFileName:filePath mode:ZipFileModeCreate];
[self performSelectorOnMainThread:@selector(log:) withObject:@"Adding first file..." waitUntilDone:YES];
ZipWriteStream *stream1= [zipFile writeFileInZipWithName:@"abc.txt" fileDate:[NSDate dateWithTimeIntervalSinceNow:-86400.0] compressionLevel:ZipCompressionLevelBest];
[self performSelectorOnMainThread:@selector(log:) withObject:@"Writing to first file's stream..." waitUntilDone:YES];
NSString *text= @"abc";
[stream1 writeData:[text dataUsingEncoding:NSUTF8StringEncoding]];
[self performSelectorOnMainThread:@selector(log:) withObject:@"Closing first file's stream..." waitUntilDone:YES];
[stream1 finishedWriting];
[self performSelectorOnMainThread:@selector(log:) withObject:@"Adding second file..." waitUntilDone:YES];
ZipWriteStream *stream2= [zipFile writeFileInZipWithName:@"x/y/z/xyz.txt" compressionLevel:ZipCompressionLevelNone];
[self performSelectorOnMainThread:@selector(log:) withObject:@"Writing to second file's stream..." waitUntilDone:YES];
NSString *text2= @"XYZ";
[stream2 writeData:[text2 dataUsingEncoding:NSUTF8StringEncoding]];
[self performSelectorOnMainThread:@selector(log:) withObject:@"Closing second file's stream..." waitUntilDone:YES];
[stream2 finishedWriting];
[self performSelectorOnMainThread:@selector(log:) withObject:@"Closing zip file..." waitUntilDone:YES];
[zipFile close];
[zipFile release];