tags:

views:

712

answers:

1

I am using a UIImagePickerController in my application.

After selecting an image by user,

image should be saved at application Documents Directory,

my Code is Give Below.

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
     [picker dismissModalViewControllerAnimated:YES];
     NSData *imgData = UIImagePNGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"]);
     UIImage *img = [[UIImage alloc] initWithData:imgData];
     stuImgView.image = img;
     [img release];

     //write image
     NSString *imageFilename = [NSString stringWithFormat:@"%i.jpg", currentStudent.stuNo];
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *path = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0], imageFilename];
     UIImage *stuImg; 
     BOOL success; 
     NSFileManager *fm=[NSFileManager defaultManager];
     // how to store file at documents dir????
}

i dont know how to use file manager to store a file?

Help me Out.

Thanks in advance.

+2  A: 

You can use writeToFile:atomically::

[imgData writeToFile:path atomically:NO];
notnoop
Nope. Something wrong.Here I need to create a new file named anyNumber.jpg.NSData won't create a file - image file. (according to me).
sugar