cocoa ios iphone xcode 播放GIF动画
2012-12-06 10:24
323 查看
使用imageio的这个自带的framework, 这个库也是apple的webkit所使用的,可以参考apple的opensource的webkit实现。 因此,这个 库从性能和蒹容性方面应该都是最佳选择
以下是代码,比较简单
解压完之后,直接用IMageview就可以播放了。代码如下。
以下是代码,比较简单
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,0,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]
相关文章推荐
- iPhone上用OpenGL实现gif图片动画播放的代码
- iPhone How-to:播放gif动画
- iPhone How-to:播放gif动画
- iPhone 播放Gif动画
- iPhone开放播放gif动画
- iOS 简单实现gif动画播放
- 网页中的gif动画无法正常播放
- iOS Gif动画播放
- gifplayer-可控制GIF动画图片播放和暂停jQuery插件
- android中播放gif动画之二
- Android 播放Gif 动画
- wxwidgets中分解GIF动画图片并显示播放
- iphone 如何播放多张图片组成的动画
- 易语言设置在图片框中播放GIF动画的方法
- VB利用PictureBox控件播放GIF动画
- Delphi 2005 以上版本GIF动画播放设置
- [RK3288][Android6.0] 调试笔记 --- 播放GIF动画卡顿问题
- Android播放GIF动画
- ios中播放gif动画
- 想控制GIF图片动画播放吗?试试gifffer.js