我有一张UIImage图片,它是一个GIF文件。
我需要将它转换成NSData对象。 但是它需要保持为GIF格式,因此我不能使用UIImageJPEGRepresentation。
有什么想法吗?
我有一张UIImage图片,它是一个GIF文件。
我需要将它转换成NSData对象。 但是它需要保持为GIF格式,因此我不能使用UIImageJPEGRepresentation。
有什么想法吗?
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSData *data = [NSData dataWithContentsOfURL:[self getCurrentGIFURL]];
[library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {}
NSData
对象而不是将其作为UIImage
,它将保持动画效果。NSData *gifData = [NSData dataWithContentsOfFile:@"myCoolPic.gif"];
NSString* gifPath = [[NSBundle mainBundle] pathForResource:@"ajax-loader" ofType:@"gif"];
,并将此字符串提供给上述函数。 - Martin Berger