I am developing an app, where i am accessing the saved photoalbum of iphone.
After accessing i am storing the same in the documents directory.
Now when i try to access the image from document directory, i am getting the null image....
I think the way i am storing the image is not proper.
I am attaching the code for your reference....Pls help....
I am accessing the image like this:
After accessing i am storing the same in the documents directory.
Now when i try to access the image from document directory, i am getting the null image....
I think the way i am storing the image is not proper.
I am attaching the code for your reference....Pls help....
Code:
#pragma mark -
#pragma mark imagepicker delegate method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
self.cameraAlbumPicker.view.hidden = YES;
self.imgViewDisplayImage.hidden = NO;
NSData *imageData=[NSData dataWithData:UIImagePNGRepresentation(image)];
UIImage *img=[[UIImage alloc] initWithData:imageData];
self.imgViewDisplayImage.image = img;
[img release];
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *directoryPath=[[paths objectAtIndex:0] stringByAppendingPathComponent:@"User Image"];
NSString *filePath=[directoryPath stringByAppendingPathComponent:@"image.png"];
[imageData writeToFile:filePath atomically:YES];
NSLog(@"filePath:%@",filePath);
}
I am accessing the image like this:
Code:
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *directoryPath=[[paths objectAtIndex:0] stringByAppendingPathComponent:@"User Image"];
NSString *filePath=[directoryPath stringByAppendingPathComponent:@"image.png"];
while ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSLog(@"File exists");
UIImage *image = [UIImage imageWithContentsOfFile:filePath];
}