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

  • SEARCH
  • Home
  • 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 7877393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:21:21+00:00 2026-06-03T03:21:21+00:00

I am trying to save a UIImage but it gives me an error. The

  • 0

I am trying to save a UIImage but it gives me an error. The UIImage is picked from the UIImagePickerController and is then saved by making an NSData out of it and call writeToFile: on this NSData object.
When doing so, I will get an error. The same method stores other images perfectly. The images which I have no problem storing retrieved from a website as a byte array and is then converted to a UIImage and is then saved.
It seems that the issue is specific for images from the UIImagePickerController.

Can anybody tell me how I can fix this?

It seems that the images from the UIImagePickerController is saved fine but I still get this error which causes the application to crash:

May 1 10:38:05 Simon-BS-iPhone Diims[619] : ImageIO: JPEG
Corrupt JPEG data: premature end of data segment

This is the code used to save the image:

+ (void)storeImage:(UIImage *)image name:(NSString *)name
{
    NSString *pathForCache = [self pathForCache];
    NSData *imageData = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0f)];
    NSString *jpegPath = [pathForCache stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpeg", name]];

    NSError *error;
    if ([imageData writeToFile:jpegPath options:NSDataWritingAtomic error:&error] == NO)
    {
        DLog(@"Could not save image: %@", jpegPath);
        DLog(@"%@", error);
    }
}

It is called like this when an image is selected:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    // Close controller
    [picker dismissModalViewControllerAnimated:YES];

    // Save image
    self.selectedDevice.image = image;
    [CDeviceManager localUpdateDevice:self.selectedDevice delegate:self];
}
  • 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-03T03:21:23+00:00Added an answer on June 3, 2026 at 3:21 am

    Try changing your code as follows if it works:-

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
     {
           // Save image self.selectedDevice.image = image;
           [CDeviceManager localUpdateDevice:self.selectedDevice delegate:self];
    
           // Close controller [picker dismissModalViewControllerAnimated:YES];
           //dismiss after saving the image
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out how I can shrink and save a UIImage,
I'm trying to save some information from a user that is saved on the
Trying to save output from this script to a file based on a cell
Im trying to save a simple script in netbeans to htdocs, but i only
I am trying to save a histogram to file in R from my Virtual
trying to save a step and combine these two queries but not sure how
When trying to save my SSIS packages from my vs 2008 to my sql
I am trying to save a rotated and scaled UIImageView as an UIImage in
I am trying to save a image by picking it from iphone photo library.
I am trying to save a list of users (with UIImage property) to NSUserdefault

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.