Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8636927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:20:59+00:00 2026-06-12T10:20:59+00:00

Trying to select image using photo picker and save that image internally in apps

  • 0

Trying to select image using photo picker and save that image internally in apps folder.

- (void) imagePickerController: (UIImagePickerController *) pickerdidFinishPickingMediaWithInfo: (NSDictionary *) info {

NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
UIImage *originalImage, *editedImage, *imageToUse;

// Handle a still image picked from a photo album
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0)
    == kCFCompareEqualTo) {

    editedImage = (UIImage *) [info objectForKey:
                               UIImagePickerControllerEditedImage];
    originalImage = (UIImage *) [info objectForKey:
                                 UIImagePickerControllerOriginalImage];

    if (editedImage) {
        imageToUse = editedImage;
    } else {
        imageToUse = originalImage;
    }
    // Do something with imageToUse

    //save it
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *imageName = [documentsDirectory stringByAppendingString:[NSString stringWithFormat:@"%d", myUniqueID]];
    NSString *imagePath = [imageName stringByAppendingPathComponent:@".png"];

    NSData *webData = UIImagePNGRepresentation(editedImage);
    NSError* error = nil;
    bool success = [webData writeToFile:imagePath options:NULL error:&error];
    if (success) {
        // successfull save
        imageCount++;
        [[NSUserDefaults standardUserDefaults] setInteger:imageCount forKey:@"imageCount"];
        NSLog(@"@Success save to: %@", imagePath);
    }
    else if (error) {
        NSLog(@"Error:%@", error.localizedDescription);
    }
}
...
}

What I can’t figure out is that writeToFile::: returns false but no value is returned in error so I can’t figure out whats going wrong. Any help would be greatly appreciated thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:21:01+00:00Added an answer on June 12, 2026 at 10:21 am

    You’re missing a “/”. The line:

    NSString *imageName = [documentsDirectory stringByAppendingString:[NSString stringWithFormat:@"%d", myUniqueID]];
    

    should be:

    NSString *imageName = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d", myUniqueID]];
    

    And the line that says:

    NSString *imagePath = [imageName stringByAppendingPathComponent:@".png"];
    

    should be:

    NSString *imagePath = [imageName stringByAppendingPathExtension:@"png"];
    

    Update:

    And, shouldn’t:

    NSData *webData = UIImagePNGRepresentation(editedImage);
    

    be the following?

    NSData *webData = UIImagePNGRepresentation(imageToUse);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to select a <div> using jquery's $('#divname') inside a infobox that
I'm trying to write code to select an image from the photo library on
I'm trying to get the cropped version of an image that's pulled using ALAsset.
Hey i can't seem to understand this error. I'm trying to select an image
alt text http://www.freeimagehosting.net/image.php?a55fa98f01.jpg Hi I am trying to use a HTML select box with
In trying to select elements that have any attributes, the following throws a jQuery
I am trying to select the last record from a table in MySQL using
I am trying save an ImageButton's path in savedInstanceState in order not lose image
I'm trying to select background image depending on the dpi, but even I can
I’m trying to get an image using the built in gallery. It works fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.