Writing photos (and other things) to disk and getting them later in iphone

Posted by ebabchick on Stack Overflow See other posts from Stack Overflow or by ebabchick
Published on 2010-03-16T08:49:47Z Indexed on 2010/03/16 8:56 UTC
Read the original article Hit count: 183

Filed under:
|
|
|
|

I'm trying to write an image to disk:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0];
    NSString* savePath = [documentsPath stringByAppendingPathComponent:@"photo"];
    BOOL result = [data writeToFile:savePath atomically:YES];
    if(result) NSLog(@"Save of photo success!");

Then, later, I try to retrieve for a table view cell image:

    NSData* getPhoto = [NSData dataWithContentsOfFile:[leaf content]];
    UIImage* myImage = [UIImage imageWithData:getPhoto];
    cell.imageView.image = myImage;

Yes, I checked to make sure the [leaf content] returns the same NSString as savePath. What else could be the problem? [NSData dataWithContentsOfFile:[leaf content]]; returns nil....

Thanks guys

© Stack Overflow or respective owner

Related posts about iphone

Related posts about nsdata