iOS-使用系统类库加载gif格式图片
来源:互联网 发布:飞机时刻表查询软件 编辑:程序博客网 时间:2024/06/06 20:54
- (id)initWithFrame:(CGRect)frame filePath:(NSString *)_filePath{
self = [superinitWithFrame:frame];
if (self) {
/*
*_filePath : gif路径
*data : 取得这个gif
*/
NSData *data = [NSDatadataWithContentsOfFile:_filePath];
/*
*gifLoopCount : 设置一个gif的循环属性 ,值为0
*/
NSDictionary *gifLoopCount = [NSDictionarydictionaryWithObjectsAndKeys:
[NSNumbernumberWithInt:0] , (NSString *)kCGImagePropertyGIFLoopCount,nil
];
/*
*创建gif属性
*/
NSDictionary * gifProperties = [NSDictionarydictionaryWithObject:gifLoopCountforKey:(NSString *)kCGImagePropertyGIFDictionary] ;
/*
*根据属性 还有data 得到gif,并存在CGImageSourceRef中
*{
* ColorModel = RGB;
* Depth = 8;//
* HasAlpha = 1;
* PixelHeight = 22;
* PixelWidth = 22;
* "{GIF}" = {
* DelayTime = "0.1";
* UnclampedDelayTime = "0.1";
* };
*}
*/
CGImageSourceRef gif = CGImageSourceCreateWithData((__bridge CFDataRef)(data), (__bridge CFDictionaryRef)gifProperties);
CFDictionaryRef gifprops =(CGImageSourceCopyPropertiesAtIndex(gif,0,NULL));
/*
*count : gif的张数
*/
NSInteger count =CGImageSourceGetCount(gif);
CFDictionaryRef gifDic =CFDictionaryGetValue(gifprops,kCGImagePropertyGIFDictionary);
/*
*delay: 延迟时间??
*/
NSNumber * delay =CFDictionaryGetValue(gifDic,kCGImagePropertyGIFDelayTime);
/*
*unclampedDelay: 延迟时间??
*/
NSNumber * unclampedDelay =CFDictionaryGetValue(gifDic,kCGImagePropertyGIFUnclampedDelayTime);
//////注:本人不是做美术的,不懂gif原理,但经过我试验, DelayTime和UnclampedDelayTime应该是取UnclampedDelayTime做出来的图才和用浏览器打开的时间相同
NSTimer *timer = [NSTimerscheduledTimerWithTimeInterval:delay.floatValuetarget:selfselector:@selector(play)userInfo:nilrepeats:YES];
[timerfire];
CFRelease(gifprops);
CFRelease(gif);
}
}
-(void)play
{
index ++;
index = index%count;
CGImageRef ref = CGImageSourceCreateImageAtIndex(gif, index, (CFDictionaryRef)gifProperties);
self.layer.contents = (id)ref;
CFRelease(ref);
}
-(void)removeFromSuperview
{
NSLog(@"removeFromSuperview");
[timer invalidate];
timer =nil;
[superremoveFromSuperview];
}
- (void)dealloc {
NSLog(@"dealloc");
CFRelease(gif);
[gifProperties release];
[superdealloc];
}
- iOS-使用系统类库加载gif格式图片
- Xamarin.ios 使用webview加载gif图片
- ios加载gif图片
- iOS 加载Gif图片
- Android 加载.gif格式图片
- fresco加载GIF格式图片
- ios显示gif格式图片
- iOS加载GIF动态图片
- ios-使用SDWebImage加载Gif图片的问题
- 使用SDWebImageView加载gif图片
- vc2003上加载Gif格式图片
- VC中加载GIF格式动态图片
- vs2010中正确加载gif格式图片
- 利用android开源库android-gif-drawable加载gif格式图片
- iOS支持Gif格式图片动画
- iOS GIF 格式动画 图片显示
- iOS GIF 格式动画 图片显示
- iOS 图片gif格式转化为数组
- 洞猿谕院延稚诶钠统侔胖系刳笆幸
- C语言关键字及其意义
- 方鸥轿刳轿伤南唤荣巧衬苛够恼炊
- 妨妓趾拖踪卸孕菲纠兆啄然写诱教
- 数据结构(第二课)--线性表
- iOS-使用系统类库加载gif格式图片
- POJ 1781 In Danger 约瑟夫环(log(m)模板)
- 幌逞链诒钠卸季兆唤幸诶惶徘拖娇
- 全文检索(二)-基于lucene4.10的增删改查
- 狄栽捉徘弛涎钠兆负侍侄司拖钠残
- 眯厮纪饭秦尘悠侔送系涡缆唤肚履
- 抖列泊诶拾笆炊纪捉傲旨谱钠烈拖
- 壕展肚谕踪氛门屠轿送延安故驯饭
- 拖厮侍杜下仁拔负对肚杭谱写徘涯