}
/* GIF图片解析 */
void getFrameInfo(NSString * string, NSMutableArray *frames, NSMutableArray *delayTimes, CGFloat *totalTime,CGFloat *gifWidth, CGFloat *gifHeight,NSUInteger loopCount)
{
NSData *data = [NSData dataWithContentsOfFile:string];
CGImageSourceRef gifSource = CGImageSourceCreateWithData((CFDataRef)data, nil);
//获取gif的帧数
size_t frameCount = CGImageSourceGetCount(gifSource);
//获取GfiImage的基本数据
NSDictionary *gifProperties = (__bridge NSDictionary ) CGImageSourceCopyProperties(gifSource, NULL);
//由GfiImage的基本数据获取gif数据
NSDictionary gifDictionary =[gifProperties objectForKey:(NSString)kCGImagePropertyGIFDictionary];
//获取gif的播放次数 0-无限播放
loopCount = [[gifDictionary objectForKey:(NSString)kCGImagePropertyGIFLoopCount] integerValue];
CFRelease((__bridge CFTypeRef)(gifProperties));
for (size_t i = 0; i < frameCount; ++i) {
//得到每一帧的CGImage
CGImageRef frame = CGImageSourceCreateImageAtIndex(gifSource, i, NULL);
[frames addObject:[UIImage imageWithCGImage:frame]];
CGImageRelease(frame);
//获取每一帧的图片信息
NSDictionary frameDict = (__bridge NSDictionary)CGImageSourceCopyPropertiesAtIndex(gifSource, i, NULL);
//获取Gif图片尺寸
if (gifWidth != NULL && gifHeight != NULL) {
gifWidth = [[frameDict valueForKey:(NSString)kCGImagePropertyPixelWidth] floatValue];
gifHeight = [[frameDict valueForKey:(NSString)kCGImagePropertyPixelHeight] floatValue];
}
if (frameCount != 1) {
//由每一帧的图片信息获取gif信息
NSDictionary gifDict = [frameDict valueForKey:(NSString)kCGImagePropertyGIFDictionary];
//取出每一帧的delaytime
[delayTimes addObject:[gifDict valueForKey:(NSString*)kCGImagePropertyGIFDelayTime]];
if (totalTime) {
*totalTime = totalTime + [[gifDict valueForKey:(NSString)kCGImagePropertyGIFDelayTime] floatValue];
}
}
CFRelease((__bridge CFTypeRef)(frameDict));
}
CFRelease(gifSource);
}
根据相关参数设置合成GIF注意也可以直接生成data而不是保存到沙盒
NSArray *delays = [gifDicInfo objectForKey:@“delays”];
//是否循环
NSUInteger loopCount = [[gifDicInfo objectForKey:@“loopCount”] integerValue];
//创建图片路径
NSString *cashPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@“animated11.gif”];
NSURL *url = [NSURL fileURLWithPath:cashPath];
CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)url, kUTTypeGIF, images.count, NULL);
// NSMutableData *data = [NSMutableData data];
// CGImageDestinationRef destination = CGImageDestinationCreateWithData((CFMutableDataRef)data, kUTTypeGIF, images.count, NULL);
NSDictionary *gifDic = @{
(NSString *)kCGImagePropertyGIFLoopCount:[NSNumber numberWithInteger:loopCount]
};
NSDictionary *gifProperties = @{
(NSString *)kCGImagePropertyGIFDictionary:gifDic
};
for (int i = 0; i < images.count; i++) {
UIImage *image = [images objectAtIndex:i];
NSDictionary *gifDict = @{
(NSString *)kCGImagePropertyGIFDelayTime:[delays objectAtIndex:i]
};
NSDictionary *frameProperties = @{
(NSString *)kCGImagePropertyGIFDictionary:gifDict
};
CGImageDestinationAddImage(destination, image.CGImage, (CFDictionaryRef)frameProperties);
CGImageDestinationSetProperties(destination, (CFDictionaryRef)gifProperties);
}
CGImageDestinationFinalize(destination);
CFRelease(destination);
NSLog(@“animated GIF file created at %@”, cashPath);
NSMutableArray *array = [NSMutableArray array];
NSData *data = [NSData dataWithContentsOfFile:cashPath];
[array addObject:data];
NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@“group.adfasf”];
[shared setObject:[array copy] forKey:@“data123”];
[shared synchronize];
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
最后
下面是辛苦给大家整理的学习路线,有需要的可以点击这里免费获取
后
下面是辛苦给大家整理的学习路线,有需要的可以点击这里免费获取
[外链图片转存中…(img-6hGukdCw-1710699289151)]