图片合成gif图 iOS
2017-02-20 17:03
861 查看
实现方法:
-(void)creatGif{
NSMutableArray * images= [[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"1"],[UIImage imageNamed:@"2"],[UIImage imageNamed:@"3"],[UIImage imageNamed:@"4"], nil];
//创建爱你gif文件
NSArray *document = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *doucmentStr =[document objectAtIndex:0];
NSFileManager *filemanager = [NSFileManager defaultManager];
NSString *textDic = [doucmentStr stringByAppendingString:@"/gif"];
[filemanager createDirectoryAtPath:textDic withIntermediateDirectories:YES attributes:nil error:nil];
NSString *path = [textDic stringByAppendingString:@"test1.gif"];
NSLog(@"-----%@",path);
//配置gif属性
CGImageDestinationRef destion;
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)path, kCFURLPOSIXPathStyle, false);
destion = CGImageDestinationCreateWithURL(url, kUTTypeGIF, images.count, NULL);
NSDictionary *frameDic = [NSDictionary dictionaryWithObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:0.3],(NSString*)kCGImagePropertyGIFDelayTime, nil] forKey:(NSString*)kCGImagePropertyGIFDelayTime];
NSMutableDictionary *gifParmdict = [NSMutableDictionary dictionaryWithCapacity:2];
[gifParmdict setObject:[NSNumber numberWithBool:YES] forKey:(NSString*)kCGImagePropertyGIFHasGlobalColorMap];
[gifParmdict setObject:(NSString*)kCGImagePropertyColorModelRGB forKey:(NSString*)kCGImagePropertyColorModel];
[gifParmdict setObject:[NSNumber numberWithInt:8] forKey:(NSString*)kCGImagePropertyDepth];
[gifParmdict setObject:[NSNumber numberWithInt:0] forKey:(NSString*)kCGImagePropertyGIFLoopCount];
NSDictionary *gifProperty = [NSDictionary dictionaryWithObject:gifParmdict forKey:(NSString*)kCGImagePropertyGIFDictionary];
for (UIImage *dimage in images) {
CGImageDestinationAddImage(destion, dimage.CGImage, (__bridge CFDictionaryRef)frameDic);
}
CGImageDestinationSetProperties(destion,(__bridge CFDictionaryRef)gifProperty);
CGImageDestinationFinalize(destion);
CFRelease(destion);
}
引入的头文件:
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
-(void)creatGif{
NSMutableArray * images= [[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"1"],[UIImage imageNamed:@"2"],[UIImage imageNamed:@"3"],[UIImage imageNamed:@"4"], nil];
//创建爱你gif文件
NSArray *document = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *doucmentStr =[document objectAtIndex:0];
NSFileManager *filemanager = [NSFileManager defaultManager];
NSString *textDic = [doucmentStr stringByAppendingString:@"/gif"];
[filemanager createDirectoryAtPath:textDic withIntermediateDirectories:YES attributes:nil error:nil];
NSString *path = [textDic stringByAppendingString:@"test1.gif"];
NSLog(@"-----%@",path);
//配置gif属性
CGImageDestinationRef destion;
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)path, kCFURLPOSIXPathStyle, false);
destion = CGImageDestinationCreateWithURL(url, kUTTypeGIF, images.count, NULL);
NSDictionary *frameDic = [NSDictionary dictionaryWithObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:0.3],(NSString*)kCGImagePropertyGIFDelayTime, nil] forKey:(NSString*)kCGImagePropertyGIFDelayTime];
NSMutableDictionary *gifParmdict = [NSMutableDictionary dictionaryWithCapacity:2];
[gifParmdict setObject:[NSNumber numberWithBool:YES] forKey:(NSString*)kCGImagePropertyGIFHasGlobalColorMap];
[gifParmdict setObject:(NSString*)kCGImagePropertyColorModelRGB forKey:(NSString*)kCGImagePropertyColorModel];
[gifParmdict setObject:[NSNumber numberWithInt:8] forKey:(NSString*)kCGImagePropertyDepth];
[gifParmdict setObject:[NSNumber numberWithInt:0] forKey:(NSString*)kCGImagePropertyGIFLoopCount];
NSDictionary *gifProperty = [NSDictionary dictionaryWithObject:gifParmdict forKey:(NSString*)kCGImagePropertyGIFDictionary];
for (UIImage *dimage in images) {
CGImageDestinationAddImage(destion, dimage.CGImage, (__bridge CFDictionaryRef)frameDic);
}
CGImageDestinationSetProperties(destion,(__bridge CFDictionaryRef)gifProperty);
CGImageDestinationFinalize(destion);
CFRelease(destion);
}
引入的头文件:
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
相关文章推荐
- iOS中GIF图片的解析+合成
- iOS GIF合成有透明通道图片重叠问题
- IOS:如何使用多张图片合成GIF
- iOS学习笔记--gif图片合成
- Android合成GIF图片JNI版
- ios 获取一个view上的图片,iphone混合图片 合成图片 任意范围截图 截屏
- iOS - GIF图的完美拆解、合成、显示
- iOS图片合成————(拍照换发)
- IOS学习之路二十四(UIImageView 加载gif图片)
- 论坛源码推荐:适用于iOS 7的图片和视频管理控件 Flipboard开源高性能动画GIF引擎
- IOS GIF图片的解析
- IOS学习之路二十四(UIImageView 加载gif图片)
- ios中用三种方式显示gif动态图片
- Android合成GIF图片JNI版
- IOS显示GIF图片
- IOS GIF图片解析 将gif图片解析成image数组
- gif图片拆帧及合成[python]实现
- IOS疯狂基础之GIF图片的显示
- iOS支持Gif格式图片动画
- iOS GIF 格式动画 图片显示