简体   繁体   中英

How to save an animated image to iPhone's photos album?

I created an animated image, and it animates properly in an UIImageView:

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIImage *image1 = [UIImage imageNamed:@"apress_logo"];
    UIImage *image2 = [UIImage imageNamed:@"Icon"];
    UIImage *animationImage = [UIImage animatedImageWithImages:[NSArray arrayWithObjects:image1, image2, nil] duration:0.5];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    imageView.image = animationImage;
    [self.view addSubview:imageView];
}

But if saved to photos album, it couldn't animate agian:

UIImageWriteToSavedPhotosAlbum(animationImage, 
                               self,
                               @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:),
                               nil);

So is there any solution to save an animated image to photos album?

Special thanks!

The photo album is an application as well, like exactly what you are making. Except to animate an image you wrote corresponding code like,

UIImage *animationImage = [UIImage animatedImageWithImages:[NSArray arrayWithObjects:image1, image2, nil] duration:0.5];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    imageView.image = animationImage;

But you assumed that your Image will be treated in similar way inside your photo album app as well. Then No thats not true. in photo album app probably the application just reading an Image from disk and then shows in inside UIImageView without any animation "BECAUSE THERE IS NO ANIMATION CODE" :)

This creates an opportunity to create a photo album with animated images.


I have seen programs like Quartz Composer creating .mov file from several images and creating animations to it. But thats professionally built by Apple. Now, I said because I think it's possible to create .mov by using API but you might have to dig deeper as I have no idea how to.

The closest reference I can find is this :

http://www.cimgf.com/2008/09/10/core-animation-tutorial-rendering-quicktime-movies-in-a-caopengllayer/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM