cocoa ios iphone xcode 播放GIF动画
来源:互联网 发布:我的校园软件 编辑:程序博客网 时间:2024/06/03 15:31
使用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,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]
- cocoa ios iphone xcode 播放GIF动画
- iPhone 播放Gif动画
- iOS 播放gif 动画
- iOS Gif动画播放
- ios播放gif动画
- iOS 播放GIF动画
- ios中播放gif动画
- ios中播放gif动画
- iOS中播放gif动画
- ios中播放gif动画
- ios中播放gif动画
- ios中播放gif动画
- ios中播放gif动画
- ios中播放gif动画
- iPhone How-to:播放gif动画
- iphone中如何播放gif动画
- iOS 简单实现gif动画播放
- iOS 简单的播放gif动画
- java多个pdf合成一个pdf
- Windows Server 2003 R2 系统服务
- 录制caf转mp3
- Android Zipalign工具
- void指针强转结构体指针问题
- cocoa ios iphone xcode 播放GIF动画
- phpcms头条图片
- ColorMatrix
- Android Intent Flag的介绍
- 基础要点总结
- 使用dma_alloc_writecombine申请内存空间大小的限制
- linux softirq和tasklet的关系
- Android APK签名流程
- [转]成都一网络公司放末日假期 称最后时间陪最亲的人