2

我需要将以编程方式捕获的屏幕截图保存到文件夹中并压缩它。那可能吗?有人帮忙

4

1 回答 1

2

第一步 - 创建屏幕截图:如何以编程方式截取屏幕截图

第二 - 保存它:如何使用 NSFileManager 将 UIImage 保存到文件中?

第三 - 压缩它。您可以使用 zlib 包装器objective-zip

已编辑:这是来自 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];
于 2012-10-12T10:39:01.007 回答