zoukankan      html  css  js  c++  java
  • Gif图片的解析

    //加载gif   
     
    02     
     
    03   NSString *filePath = [[NSBundle mainBundle]pathForResource:@"bai3" ofType:@"gif"];   
     
    04     
     
    05     NSData *data = [NSData dataWithContentsOfFile:filePath];   
     
    06     
     
    07     CGImageSourceRef gif = CGImageSourceCreateWithData((CFDataRef)data, nil);   
     
    08     
     
    09  //获取gif的各种属性   
     
    10     
     
    11     CFDictionaryRef gifprops =(CGImageSourceCopyPropertiesAtIndex(gif,0,NULL));   
     
    12     
     
    13     NSLog(@"_______%@",gifprops);   
     
    14     
     
    15     
     
    16     NSInteger count =CGImageSourceGetCount(gif);   
     
    17     
     
    18     NSLog(@"________%d",count);   
     
    19     
     
    20     
     
    21    CFDictionaryRef gifDic = CFDictionaryGetValue(gifprops, kCGImagePropertyGIFDictionary);   
     
    22     
     
    23  CFDictionaryRef delay = CFDictionaryGetValue(gifDic, kCGImagePropertyGIFDelayTime);   
     
    24     
     
    25     NSLog(@"_______%@",delay);    
     
    26     
     
    27     
     
    28  //[gifDic objectForKey:(NSString *)kCGImagePropertyGIFDelayTime];   
     
    29     
     
    30     //    NSNumber * w = CFDictionaryGetValue(gifprops, @"PixelWidth");   
     
    31     
     
    32     //    NSNumber * h =CFDictionaryGetValue(gifprops, @"PixelHeight");   
     
    33     
     
    34     //    float totalDuration = delay.doubleValue * count;   
     
    35     
     
    36     //    float pixelWidth = w.intValue;   
     
    37     
     
    38     //    float pixelHeight = h.intValue;   
     
    39     
     
    40   //将gif解析成UIImage类型对象,并加进images数组中     
     
    41     
     
    42     
     
    43     NSMutableArray *images = [NSMutableArray arrayWithCapacity:count];   
     
    44     
     
    45     for(int index=0;index<count;index++)   
     
    46     
     
    47     {   
     
    48     
     
    49         CGImageRef ref = CGImageSourceCreateImageAtIndex(gif, index, nil);   
     
    50     
     
    51         UIImage *img = [UIImage imageWithCGImage:ref];   
     
    52     
     
    53         [images addObject:img];   
     
    54     
     
    55         CFRelease(ref);   
     
    56     
     
    57     }   
     
    58     
     
    59     CFRelease(gifprops);   
     
    60     
     
    61     CFRelease(gif);  
    
  • 相关阅读:
    Queryable.Union 方法实现json格式的字符串合并
    战舰少女官方网站正式开启 -手机卡牌游戏
    星工场逆转娱乐圈预计5.1后上线
    Eclipse编辑jsp卡死解决方案
    Eclipse的workspace中放入Ext JS卡死或OOM的解决方案
    Ext Js详解指南
    Android 自定义RadioButton实现
    反编译Android APK及防止APK程序被反编译
    Android自定义控件
    优秀博客
  • 原文地址:https://www.cnblogs.com/yunis/p/4290770.html
Copyright © 2011-2022 走看看