NSString * path =[[NSBundle mainBundle]pathForResource:@"dog" ofType:@"gif"];
NSData * data =[NSData dataWithContentsOfFile:path];
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
//将gif分解成一帧帧
size_t count=CGImageSourceGetCount(source);
NSMutableArray * tmpArray =[[NSMutableArray alloc]init];
for (size_t i=0; i<count; i++) {
CGImageRef imageRef =CGImageSourceCreateImageAtIndex(source, i, NULL);
UIImage * image =[UIImage imageWithCGImage:imageRef scale:1 orientation:UIImageOrientationUp];
[tmpArray addObject:image];
}
//保存
for (int m=0; m<tmpArray.count; m++) {
NSString * savePath =[NSHomeDirectory() stringByAppendingFormat:@"/Documents/%d.png",m];
NSData * dqta =UIImagePNGRepresentation([tmpArray objectAtIndex:m]);
[dqta writeToFile:savePath atomically:YES];
}
Gif图的分解
最新推荐文章于 2024-08-08 04:02:07 发布