使用ios将图像转换为gif

时间:2013-06-08 06:16:48

标签: iphone ios

我正在尝试使用IOS Xcode 4.5以编程方式转换.gif格式的10个UIImages并将其保存在图库中,但我没有运气我甚至在stackoverflow上尝试了一个问题 Create and and export an animated gif via iOS?我不明白__bridge id所使用的变量是什么,如何将这些图像分配给方法请帮助......

2 个答案:

答案 0 :(得分:1)

而不是将图像转换为Gif apple提供了UIImageView.animationImages proparty,你可以像Gif一样逐个动画。像贝娄代码: -

UIImage *statusImage = [UIImage imageNamed:@"status1.png"];
    YourImageView = [[UIImageView alloc]
                                      initWithImage:statusImage];


    //Add more images which will be used for the animation
    YourImageView.animationImages = [NSArray arrayWithObjects:
                                         [UIImage imageNamed:@"status1.png"],
                                         [UIImage imageNamed:@"status2.png"],
                                         [UIImage imageNamed:@"status3.png"],
                                         [UIImage imageNamed:@"status4.png"],
                                         [UIImage imageNamed:@"status5.png"],
                                         [UIImage imageNamed:@"status6.png"],
                                         [UIImage imageNamed:@"status7.png"],
                                         [UIImage imageNamed:@"status8.png"],
                                         [UIImage imageNamed:@"status9.png"],
                                         nil];




         //setFrame of postion on imageView

          YourImageView.frame = CGRectMake(
                                     self.view.frame.size.width/2
                                     -statusImage.size.width/2, 
                                     self.view.frame.size.height/2
                                     -statusImage.size.height/2, 
                                     statusImage.size.width, 
                                     statusImage.size.height);


  YourImageView.center=CGPointMake(self.view.frame.size.width /2, (self.view.frame.size.height)/2);


      YourImageView.animationDuration = 1;
      [self.view addSubview:YourImageView];

答案 1 :(得分:-3)

首先,您应该在Apple文档中检查您的问题。一切都在那里。你需要的是研究与发展读即可。

你应该试试ImageIO framework。它可以将 .png文件转换为CGImageRef个对象,然后将CGImageRefs导出为 .gif文件

将图像保存到照片库:UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil); 同样记录在UIKit