我有一些相当简单的代码,可以从一组UIImages创建一个GIF图像。
它在iOS7上运行良好。在iOS8上,创建了一个文件,但是文件以某种方式损坏(在设备上或下载到桌面时不起作用)。这是示例代码:

...

float frameTime = (1/(fps * speed));

NSString *fileOutput = [NSString stringWithFormat:@"%@/%ld", NSTemporaryDirectory(), time(NULL)];

CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:fileOutput],kUTTypeGIF,[images count],NULL);

NSDictionary *frameProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:frameTime] forKey:(NSString *)kCGImagePropertyGIFDelayTime],(NSString *)kCGImagePropertyGIFDictionary,kCFBooleanFalse,kCGImagePropertyHasAlpha,[NSNumber numberWithFloat:1.0],kCGImageDestinationLossyCompressionQuality, nil];

NSMutableDictionary *gifProps = [NSMutableDictionary dictionary];
[gifProps setObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCGImagePropertyGIFHasGlobalColorMap];
[gifProps setObject:[NSNumber numberWithInt:0] forKey:(NSString*)kCGImagePropertyGIFLoopCount];
[gifProps setObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCGImagePropertyHasAlpha];
[gifProps setObject:[NSNumber numberWithFloat:1.0] forKey:(NSString*)kCGImageDestinationLossyCompressionQuality];

NSDictionary *gifProperties = [ NSDictionary dictionaryWithObject:gifProps forKey:(NSString*) kCGImagePropertyGIFDictionary ];

for (int i = 0; i<[images count]; i++)
{
    UIImage *im = [UIImage imageNamed:[images objectAtIndex:i]];

    @autoreleasepool
    {
        CGImageDestinationAddImage(destination, im.CGImage, (__bridge CFDictionaryRef)frameProperties);
        im = nil;
    }
}

CGImageDestinationSetProperties(destination, (__bridge CFDictionaryRef)gifProperties);
CGImageDestinationFinalize(destination);
CFRelease(destination);

...

没有警告消息,也没有执行错误。
是什么原因引起的?

最佳答案

苹果确认这是一个iOS8错误,已提交(18512475)。

10-04 21:56
查看更多