Archiving UIImage?


#1

Hello,

I tried messing around a bit to see if you couldn’t just simply Archive down UIImage objects, since i believe that archiving is more simple than a binary write. I did it like this (in a new test application)

Unarchive / initWithCoder

[code]-(id) initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self) {
[self setImage:[UIImage imageWithData:[aDecoder decodeObjectForKey:@“image”]]];
}

return self;

}[/code]

Encode

-(void) encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:UIImagePNGRepresentation(_image) forKey:@"image"]; }

Now, this actually work’s, except something weird is going on, and i was wondering if this was the reason to use a binary read instead?

First off, i think the application is running slow, even with just 3 images?
And second, the images rotate themselves after being saved? if you take a photo in portrait, it will be displayed in portrait throughout program execution. However, when you kill the application and load it back in, they are displayed in landscape, as if you took them that way? obviously you could just programmatically rotate the images, but i was wondering why this is happening?

Thanks on advance :slight_smile: hope you can help me with this, as i am actually looking for clarification on which type of saving you should do?


#2

That it way too much data to store in one file and load into memory all at once - this is why things are running slow. In a later chapter, you’ll store thumbnails of the image becuase those are pretty small.