将UIImage转换为NSData,但保留为GIF文件 [英] Convert a UIImage into NSData BUT stay as a GIF file
本文介绍了将UIImage转换为NSData,但保留为GIF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UIImage是一个GIF文件。
I have a UIImage which is a GIF file.
我需要使它成为一个NSData对象。
但是它需要保留一个GIF,所以我不能使用UIImageJPEGRepresentation。
I need to make it make it into an NSData object. But it needs to stay a GIF so I can't use UIImageJPEGRepresentation.
任何想法?
推荐答案
我遇到了你提到的同样的问题,这里是我用来保存动画的GIF到照片,而不会失去动画的代码:
I faced the same issue you mention and here is the code i used to save the animated gif to Photos without losing animation:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSData *data = [NSData dataWithContentsOfURL:[self getCurrentGIFURL]];
[library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {}
基本上,如果您将URL或文件中的gif直接保存为 NSData
对象,而不是使其成为 UIImage
,它会保留动画。
Basically, if you save the gif from URL or from file directly as an NSData
object instead of making it a UIImage
, it will keep the animation.
这篇关于将UIImage转换为NSData,但保留为GIF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文