views:

248

answers:

1

I'm trying to save a UIIMage and then retrieve it and display it. I've been successful by saving an image in the bundle, retrieving it from there and displaying. My problem comes from when I try to save an image to disk (converting it to NSData), then retrieving it. I convert the image to NSData like so...

NSData* topImageData = UIImageJPEGRepresentation(topImage, 1.0);

then I write it to disk like so...

[topImageData writeToFile:topPathToFile atomically:NO];

then I tried to retrieve it like so...

topSubView.image = [[UIImage alloc] initWithContentsOfFile:topPathToFile];

which returns no image (the size is zero). so then I tried...

NSData *data = [[NSData alloc] initWithContentsOfFile:topPathToFile];
topSubView.image = [[UIImage alloc] initWithData:data];

to no avail. When I step through the debugger I do see that data contains the correct number of bytes but I'm confused as to why my image is not being created. Am I missing a step? Do I need to do something with NSData before converting to an image?

Greatly appreciate the help!

A: 

You should be able to use class methods of UIImage

[UIImage imageWithContentsOfFile:topPathToFile]; 

OR

[UIImage imageWithData:data];

Did that not work?

Hope this helps!

peacefulfire
Thanks for the response but I got the same result. Still no image. I'm really stumped right now.
bruin