gpt4 book ai didi

iphone - CGImageDestination 和文件命名问题

转载 作者:行者123 更新时间:2023-12-03 17:15:38 27 4
gpt4 key购买 nike

我正在使用 AVCapture 从相机捕获图像,因为我需要速度,而标准套件的速度太慢了。我遇到问题,正在输出的文件(动画 GIF)的文件名被 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% 的时间它工作正常。然而,它阻止了代码进一步工作,我在表格 View 中列出了它们并进行预览。

有谁知道为什么以及如何阻止它这样做?

代码如下:

- (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];
}

最佳答案

据我所知,这是 CGImageDestinationFinalize 制作的临时文件,您看到它们的原因是 CGImageDestinationFinalize 失败。我认为,如果您检查文件大小,您会发现名称损坏的文件大小为 0。

收到这些文件后我开始检查是否成功:)

bool success =  CGImageDestinationFinalize(destination);
CFRelease(destination);
if (success) {
NSLog(@"animated GIF file created at %@", path);
} else {
NSLog(@"failed to create gif at %@", path);
}

关于iphone - CGImageDestination 和文件命名问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7301718/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com