Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gowdalokeshs

macrumors member
Original poster
Aug 31, 2010
32
0
bangalore
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....

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]; 
	}
 
Apply basic debugging skills.

Confirm that everything else before reading the file works.

Is the image being written to the file?
How would you test this?
What does NSData's writeToFile methods return?

If the image isn't being written to the file, why not?
Does the pathname exist?
Do all directories leading to the file exist?
If not, what should you do to create them?

If the image is being written to the file, is it the right size?
It should be identical to the original image-file it was copied from, right?
Does the file contain the right data?
Again, it should be identical to the original.

If the file exists, why are you looping with a 'while' statement?
Are you expecting a file to disappear by itself?
What will happen if the file exists?
What purpose does an infinite loop serve?
 
Can you please tell me how to check this directory ?

My image is getting stored in this file path. How can i check this directory ?


/var/mobile/Applications/DDE8A6D1-4569-4D06-9891-C22B15FF282C/Documents
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.