ios - Is it possible to use NSKeyedArchiver to store an animated UIImage? -
i loaded image using frames downloaded web server.
nsarray* frames = [self fetchframesfromserver]; imageview.image = [uiimage animatedimagewithimages:frames duration:1.0]; whenever try archive these frames, encoding function returns no:
bool success = [nskeyedarchiver archiverootobject:(frames) tofile:archivepath]; whenever try archive image, encoding function returns no:
bool success = [nskeyedarchiver archiverootobject:(imageview.image) tofile:archivepath]; is possible, or missing caveat of archiverootobject requires uiimage loaded bundle, in png-format, or non-animated?
just fyi, archivepath when printed out in debugger is
nspathstore2 * @"/var/mobile/containers/data/application/e475e3c1-4e3f-43d6-ad66-0f98320cf279/library/private documents/assets/a/b/c.archive"   0x000000012c555a60 update:
i storing individual frames of animation inside for-loop, following:
+ (void) saveimage:(uiimage*)inputimage     withsuffix:(nsstring*)filesuffix { if (inputimage == nil) {     nslog(@"error: input image nil!");     return; }  // strip away intermediate folders 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 %@ saved!", filesuffix); }  but on nskeyedarchiver line, "malloc: *** error object 0x178202340: freeing unallocated pointer"
first convert image nsdata , try archiving it
nsdata* data = uiimagepngrepresentation(imageview.image); bool success = [nskeyedarchiver archiverootobject:data tofile:archivepath]; in case of nsarray, archiving possible if objects of array conforms nscoding protocol. if array has custom object refer custom object archiving on how conform nscoding.
update
if objects of array frames of type cgrect can use nsstringfromcgrect() , cgrectfromstring() store , retrieve them.
Comments
Post a Comment