Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring image using NSDocumentDirectory not working?
    primarykey
    data
    text
    <p>I'm developing this application for an iPad. My first screen will show 2 UIImageView (ImageView, ImageView2) and 2 UIButton (Confirm, Browse).</p> <p>I will give a brief description of what my application does. When the 'Browse' button is tapped, it will show photos from my iPad's photo gallery. When a photo is selected, the photo gallery will be dismissed and 'ImageView' will show the selected photo. When the 'Confirm' button is tapped, it will store the image into my application's project by using the NSDocumentDirectory. After that, it will retrieve the photo which is saved and display it on 'ImageView2'.</p> <p>Browse Button..</p> <pre><code>- (IBAction) browsePhoto:(id)sender { UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePickerController]; [popover setPopoverContentSize:CGSizeMake(320,320)]; [popover presentPopoverFromRect:CGRectMake(200,200,-100,-100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; self.popoverController = popover; [imagePickerController release]; } </code></pre> <p>Displaying selected image on ImageView..</p> <pre><code>- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo { [self.popoverController dismissPopoverAnimated:YES]; imageView.image = selectedImage; } </code></pre> <p>Confirm Button..</p> <pre><code>- (IBAction) confirmPhoto:(id)sender { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [paths objectAtIndex:0]; NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:@"SavedImage.png"]; UIImage *image = imageView.image; NSData *imageData = UIImagePNGRepresentation(image); [imageData writeToFile:savedImagePath atomically:NO]; imageView2.image = [UIImage imageNamed:@"SavedImage.png"]; } </code></pre> <p>I'm able to view photos from the photo gallery, select a photo, and making the 'ImageView' show the selected photo. But when i tap on 'Confirm' button, 'ImageView2' doesn't display the photo. I have no idea where the problem lies at. </p> <p>Is the photo even saved? Or the way i used to retrieve the saved photo is wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload