1、创建图像目标
CGImageDestinationRef destination;
/* path */
3、创建CFURLRef对象
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)path, kCFURLPOSIXPathStyle, NO);
destination = CGImageDestinationCreateWithURL(url, kUTTypeGIF, mArray.count, nil);
NSDictionary *frameProperties = [NSDictionary dictionaryWithObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:0.18],(NSString *)kCGImagePropertyGIFDelayTime, nil] forKey:(NSString *)kCGImagePropertyGIFDictionary]; //设置gif信息 NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:2]; [dict setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCGImagePropertyGIFImageColorMap]; [dict setObject:(NSString *)kCGImagePropertyColorModelRGB forKey:(NSString *)kCGImagePropertyColorModel]; [dict setObject:[NSNumber numberWithInt:8] forKey:(NSString *)kCGImagePropertyDepth]; [dict setObject:[NSNumber numberWithInt:0] forKey:(NSString *)kCGImagePropertyGIFLoopCount]; NSDictionary *gifProperties = [NSDictionary dictionaryWithObject:dict forKey:(NSString *)kCGImagePropertyGIFDictionary];6、合成gif(把所有图片遍历添加到图像目标)
for (UIImage *dImg in mArray) { CGImageDestinationAddImage(destination, dImg.CGImage, (__bridge CFDictionaryRef)frameProperties); }
CGImageDestinationSetProperties(destination, (__bridge CFDictionaryRef)gifProperties);
CGImageDestinationFinalize(destination);9、释放目标图像
CFRelease(destination);