我使用从 Web 服务器下载的帧加载了图像。
NSArray* frames = [self fetchFramesFromServer];
imageView.image = [UIImage animatedImageWithImages:frames duration:1.0];
每当我尝试归档这些帧时,编码函数都会返回 NO:
BOOL success = [NSKeyedArchiver archiveRootObject:(frames) toFile:archivePath];
每当我尝试存档图像时,编码函数也会返回 NO:
BOOL success = [NSKeyedArchiver archiveRootObject:(imageView.image) toFile:archivePath];
这是否可能,或者我是否遗漏了一些需要从包中加载 UIImage、以 png 格式或非动画形式的 archiveRootObject 警告?
仅供参考,在调试器中打印出的 archivePath 是
NSPathStore2 * @"/var/mobile/Containers/Data/Application/E475E3C1-4E3F-43D6-AD66-0F98320CF279/Library/Private Documents/assets/a/b/c.archive" 0x000000012c555a60
更新:
我将动画的各个帧存储在 for 循环中,但我得到以下信息:
+ (void) saveImage:(UIImage*)inputImage
withSuffix:(NSString*)fileSuffix
{
if (inputImage == nil) {
NSLog(@"ERROR: input image is nil!");
return;
}
// strip away intermediate folders to avoid over-nesting
// ex: __F1/MF/FR/1_MF_FR_Animation_a1.png
// ===> 1_MF_FR_Animation_a1.png
NSString* suffixStub = [MyDatabase stubOfFilepath:fileSuffix];
NSURL* url = [MyDatabase folderURL];
NSURL* imageURL = [url URLByAppendingPathComponent:suffixStub];
NSData* pngData = UIImagePNGRepresentation(inputImage);
[NSKeyedArchiver archiveRootObject:pngData toFile:imageURL.path];
pngData = nil;
NSLog(@"Image %@ successfully saved!", fileSuffix);
}
但是在 NSKeyedArchiver 行上,我得到“malloc: *** error for object 0x178202340: Freeing unallocated pointer”