http://pojos-devlog.blogspot.com/2005/08/saving-animated-gif-using-coregraphics.html
iOS 4以降でよければImageIOフレームワークが使えるためむちゃくちゃ簡単です。任意のUIImage / CGImageRefから好きなようにアニメーションGIFを生成できます。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
#import <ImageIO/ImageIO.h> | |
#import <MobileCoreServices/MobileCoreServices.h> | |
- (void)exportAnimatedGif | |
{ | |
UIImage *shacho = [UIImage imageNamed:@"shacho.png"]; | |
UIImage *bucho = [UIImage imageNamed:@"bucho.jpeg"]; | |
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"animated.gif"]; | |
CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)[NSURL fileURLWithPath:path], | |
kUTTypeGIF, | |
2, | |
NULL); | |
NSDictionary *frameProperties = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:2] forKey:(NSString *)kCGImagePropertyGIFDelayTime] | |
forKey:(NSString *)kCGImagePropertyGIFDictionary]; | |
NSDictionary *gifProperties = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:0] 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); | |
} |
iOS 3以前の場合は・・・頑張れとしか・・・