【发布时间】:2012-04-23 18:06:00
【问题描述】:
当我尝试使用 GCD 将 UIImage 保存为 PNG 文件时遇到问题。 这就是我要写的:
NSString *fileName = [[NSString stringWithFormat:@"%@.png",url] substringFromIndex:5];
dispatch_queue_t queue = dispatch_queue_create("screenshotQueue", NULL);
dispatch_async(queue, ^{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName];
[fileManager createFileAtPath:filePath contents:UIImagePNGRepresentation(image) attributes:nil];
});
dispatch_release(queue);
这是第一次工作,但其他时候我没有创建任何内容。这个 %@.png 很奇怪,因为我创建的唯一文件无法被 Finder 识别。我必须在文件中添加 .png 扩展名(所以 filename.png.png)然后我可以打开它。
【问题讨论】:
标签: ios uiimage grand-central-dispatch nsfilemanager