IPHONE GIF播放的方式

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 13:39 点击:

1.UIWebView 播放(无法控制周期)

.h

 @interface webViewController : UIViewController { 
    IBOutlet UIWebView *WebView; 
    IBOutlet UINavigationBar *Nav; 

@property (nonatomic, retain) IBOutlet UIWebView *WebView; 
@end 

.m

 - (void)viewDidLoad { 
    [super viewDidLoad]; 
    [WebView setOpaque:NO]; 
    [WebView setBackgroundColor:[UIColor clearColor]]; 
    Nav.topItem.title=@"Welcome"; 
    Nav.topItem.leftBarButtonItem=nil;   
    NSString* gifFileName = @"j_0002.gif"; 
    NSMutableString* htmlStr = [NSMutableString string]; 
    [htmlStr appendString:@"Hello Honey"]; 
    [htmlStr appendString:@"<p><img src=\""]; 
    [htmlStr appendFormat:@"%@",gifFileName]; 
    [htmlStr appendString:@"\" alt=\"picture\"/>"]; 
    [WebView loadHTMLString:htmlStr baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]]; 
} www.2cto.com

2.glgif提供的开源代码实现(目前无法控制周期,需要自己再研究)


3.使用UIView的animation接口实现(GIF需要整理出每张图片)

动画可以用UIImageView,把动画的每一帧做成图片,转换成UIImage保存在animationImages数组中,调用- (void)startAnimating;就能看到动画


4.把GIF的通过GIF的格式转换成每张图片,通过UIView的animation的接口实现(GIF的格式貌似还是有问题,有部分图片的背景有问题)

view plain
- (NSMutableArray*)getImgArrayByName:(NSString*)name 

    //happybaby20 
    NSURL *threeUrl =[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"crad"  
                                                                            ofType:@"gif"]]; 
    NSData* data = [[NSData alloc]initWithContentsOfURL:threeUrl]; 
    NSMutableArray* array = nil; 
//  long word = ::SizeofResource(handle,hrsrc); 
//  char* lpBy = (char*)LoadResource(handle,hrsrc); 
    DWORD word = data.length; 
    BYTE* lpBy = (BYTE*)data.bytes; 
    //每张图保存的指针 需要释放 
    BYTE* pByte[100] = {0}; 
    //每张图的大小 
    DWORD nu[100] = {0}; 
    //图片数量 
    int num = 0; 
    DWORD firstLocation = 0; 
    for(DWORD j=0;j<word;j++) 
    { 
        if(lpBy[j]==0x2c) 
        { 
            if(lpBy[j-1]==0x00) 
            {                
                if(num==0) 
          

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • Lexical or Preprocessor Issue 'xxx.h
      • ios学习笔记(二)xcode 4.3.2下实现基本交互
      • ios版本的helloworld
      • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
      • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
      • IOS类似iphone通讯录TableView的完整demo【附源码】
      • UITableView一些方法
      • [iPhone中级]iPhone团购信息客户端的开发 (二)
      • 如何为Iphone应用创建启动界面
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1