将生成的GIF保存到相机胶卷? [英] Save generated GIF to camera roll?

查看:139
本文介绍了将生成的GIF保存到相机胶卷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢阅读。我使用这个问题中的方法创建了一个GIF:

Thanks for reading. I've created a GIF using methods from this question:

通过iOS创建和导出动画gif?

我正在尝试使用唯一的似乎能够将非JPG / PNG图像保存到相机胶卷的方法, ALAssetLibrary 's writeImageDataToSavedPhotosAlbum:metadata:completionBlock:

I'm trying to use the only method that appears to be able to save non JPG/PNG images to the camera roll, ALAssetLibrary's writeImageDataToSavedPhotosAlbum:metadata:completionBlock:

我将Gif保存到临时目录,如下所示:

I save the Gif to the temp Directory like this:

NSString *exportPath = [NSTemporaryDirectory() stringByAppendingString:@"/animated.gif"];
NSURL *fileURL = [NSURL fileURLWithPath:exportPath isDirectory:NO];

然后访问 NSData ,如:

NSData * gifData = [NSData dataWithContentsOfFile:fileURL.absoluteString];

创建GIF,因为我能够在 UIImageView中显示它,但是当我尝试保存它时,该方法返回成功(没有错误)但实际上没有保存(返回 Nil NSURL * assetURL 并且不会出现在相机胶卷中。

The GIF is created as I'm able to display it in a UIImageView, but when I try to save it, the method returns as a success (no error) but doesn't actually save (returns Nil for the NSURL * assetURL and does not appear in the camera roll).

如何获取我的GIF成功保存到相机胶卷?

推荐答案

我发现问题是我无法抓住来自文件的GIF。我从使用 CGImageDestinationCreateWithURL 切换到 CGImageDestinationCreateWithData 并使用 CFMutableDataRef 保存Gif数据。我不知道为什么,但是用 writeImageDataToSavedPhotosAlbum 工作来保存到相机胶卷。

I found the issue was that I was unable to actually grab the GIF from the file. I switched from using CGImageDestinationCreateWithURL to CGImageDestinationCreateWithData and used a CFMutableDataRef to hold the Gif data. I don't know why, but that made saving to camera roll with writeImageDataToSavedPhotosAlbum work.

这篇关于将生成的GIF保存到相机胶卷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆