使用多张PNG、JPG、JPEG等图片合成最终的动态GIF
UIImage *shacho = [UIImageimageNamed:@"2013_01_06_11_01_86.png"];
UIImage *bucho = [UIImageimageNamed:@"2013_01_06_11_01_93.png"];
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"animated4.gif"];
CGImageDestinationRef destination =CGImageDestinationCreateWithURL((CFURLRef)[NSURLfileURLWithPath:path], kUTTypeGIF, 2, NULL);
NSDictionary *frameProperties = [NSDictionarydictionaryWithObject:[NSDictionarydictionaryWithObject:[NSNumbernumberWithFloat:0.2f] forKey:(NSString *)kCGImagePropertyGIFDelayTime] forKey:(NSString *)kCGImagePropertyGIFDictionary];
NSDictionary *gifProperties = [NSDictionarydictionaryWithObject:[NSDictionarydictionaryWithObject:[NSNumbernumberWithInt:1] forKey:(NSString *)kCGImagePropertyGIFLoopCount]forKey:(NSString *)kCGImagePropertyGIFDictionary];
CGImageDestinationAddImage(destination, shacho.CGImage, (CFDictionaryRef)frameProperties);
CGImageDestinationAddImage(destination, bucho.CGImage, (CFDictionaryRef)frameProperties);
CGImageDestinationSetProperties(destination, (CFDictionaryRef)gifProperties);
CGImageDestinationFinalize(destination);
CFRelease(destination);
NSLog(@"animated GIF file created at %@", path);