cocoa ios iphone xcode 播放GIF动画

cocoa ios iphone xcode 播放GIF动画,第1张

概述使用imageio的这个自带的framework, 这个库也是apple的webkit所使用的,可以参考apple的opensource的webkit实现。 因此,这个 库从性能和蒹容性方面应该都是最佳选择 以下是代码,比较简单  NSDictionary *gifLoopCount = [NSDictionary dictionaryWithObjectsAndKeys:

使用imageio的这个自带的framework,这个库也是apple的webkit所使用的,可以参考apple的opensource的webkit实现。 因此,这个 库从性能和蒹容性方面应该都是最佳选择

以下是代码,比较简单 


NSDictionary *gifLoopCount = [NSDictionary dictionaryWithObjectsAndKeys:                                  [NSNumber numberWithInt:0],(Nsstring *)kCGImagePropertyGIFLoopCount,nil                                  ];        NSDictionary * gifPropertIEs = [NSDictionary dictionaryWithObject:gifLoopCount forKey:(Nsstring *)kCGImagePropertyGIFDictionary] ;        CGImageSourceRef gif = CGImageSourceCreateWithData((__brIDge  CFDataRef)(data),(__brIDge  CFDictionaryRef)gifPropertIEs);            CFDictionaryRef gifprops =(CGImageSourcecopyPropertIEsAtIndex(gif,NulL));        NSInteger count =CGImageSourceGetCount(gif);        CFDictionaryRef  gifDic = CFDictionaryGetValue(gifprops,kCGImagePropertyGIFDictionary);//[gifprops objectForKey:(Nsstring *)kCGImagePropertyGIFDictionary];        NSNumber * delay = CFDictionaryGetValue(gifDic,kCGImagePropertyGIFDelayTime); //[gifDic objectForKey:(Nsstring *)kCGImagePropertyGIFDelayTime];    NSNumber * w = CFDictionaryGetValue(gifprops,@"PixelWIDth");    NSNumber * h =CFDictionaryGetValue(gifprops,@"PixelHeight");    totalDuration  = delay.doubleValue * count;    pixelWIDth = w.intValue;    pixelHeight = h.intValue;          images = [[NSMutableArray alloc] init];    for(int index=0;index<count;index++)    {        CGImageRef ref = CGImageSourceCreateImageAtIndex(gif,index,nil);        UIImage *img = [UIImage imageWithCGImage:ref];        [images addobject:img];        CFRelease(ref);    }        CFRelease(gifprops);    CFRelease(gif);

解压完之后,直接用IMagevIEw就可以播放了。代码如下。

    UIImageVIEw *image = ....; 
    image.animationDuration = totalDuration;    image.animationImages = images;    [image startAnimating]
总结

以上是内存溢出为你收集整理的cocoa ios iphone xcode 播放GIF动画全部内容,希望文章能够帮你解决cocoa ios iphone xcode 播放GIF动画所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1053741.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存