0
我从相机捕获图像,使用AVCapture,因为我需要速度,标准套件的速度太慢。 我有问题,其中正在输出的文件(动画GIF)是由CGImageDestination函数的文件名损坏...CGImageDestination和文件命名问题
当我输出NSURL(强制转换为CFURLRef)到日志我得到路径/文件名我打算:
2011-09-04 20:40:25.914 Mover[3558:707] Path as string:.../Documents/91B2C5E8-F925-47F3-B539-15185F640828-3558-000003327A227485.gif
然而,一旦文件被创建并保存它实际上列出了文件名,因为这:
2011-09-04 20:40:25.960 Mover[3558:707] file: .91B2C5E8-F925-47F3-B539-15185F640828-3558-000003327A227485.gif-TtNT
看到区别?开始的时间和4个字符的后缀? 真的很奇怪的是,它不总是做到这一点,约40%的时间,它的工作确定。但是,它阻止了代码进一步工作,我在列表视图中列出预览。
有谁知道为什么以及如何阻止它做到这一点?
下面的代码:
- (void)exportAnimatedGif{
NSString *guidPath = [[NSProcessInfo processInfo] globallyUniqueString];
NSString *tmpPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:guidPath];
NSString *path = [tmpPath stringByAppendingPathExtension:@"gif"];
NSLog(@"Path as string:%@", path);
CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)[NSURL fileURLWithPath:path], kUTTypeGIF, [captureArray count], NULL);
NSDictionary *frameProperties = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:testDisplay3.displayValue] forKey:(NSString *)kCGImagePropertyGIFDelayTime]
forKey:(NSString *)kCGImagePropertyGIFDictionary];
NSDictionary *gifProperties = [NSDictionary dictionaryWithObject:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:2], (NSString *)kCGImagePropertyGIFLoopCount,
[NSNumber numberWithFloat:testDisplay3.displayValue], (NSString*)kCGImagePropertyGIFDelayTime,
[NSNumber numberWithFloat:testDisplay3.displayValue], (NSString*)kCGImagePropertyGIFUnclampedDelayTime,
nil]
forKey:(NSString *)kCGImagePropertyGIFDictionary];
for (int ii = 0; ii < [captureArray count]; ii++)
{
UIImage *tmpImg = [[UIImage alloc] init];
tmpImg = [captureArray objectAtIndex:ii];
CGImageDestinationAddImage(destination, tmpImg.CGImage, (CFDictionaryRef)frameProperties);
}
CGImageDestinationSetProperties(destination, (CFDictionaryRef)gifProperties);
CGImageDestinationFinalize(destination);
CFRelease(destination);
//TEST OUTPUT GENERATED FILES
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] error:nil];
for (int xx = 0; xx < [contents count]; xx++)
{
NSLog(@"file: %@", [contents objectAtIndex:xx]);
}
//END TEST CODE
[captureArray removeAllObjects];
}
添加调试行以查看从NSSearchPathForDirectoriesInDomains'返回的路径数您正在访问此方法两次,第二次可能会返回不同的过时路径。这个函数可以返回多个路径,我不认为他们会以什么顺序保证。尝试访问第一个对象而不是最后一个。另外,请确保您在开始时只访问此功能一次,并将路径存储在ivar中。这样你就可以保证两次获得相同的路径。 –