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 6706345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:30:35+00:00 2026-05-26T07:30:35+00:00

I have a view with some fields (name, price, category) and a segmented control,

  • 0

I have a view with some fields (name, price, category) and a segmented control, plus this button to take picture.

If I try this on the simulator (no camera) it works properly: I can select the image from the camera roll, edit it and go back to the view, which will show all the fields with their contents .

But on my iphone, when I select the image after the editing and go back to the view, all the fields are empty exept for the UIImageView.
I also tried to save the content of the fields in variables and put them back in the “viewWillApper” method, but the app crashes.

Start to thinking that maybe there is something wrong methods below

EDIT

I found the solution here. I defined a new method to the UIImage class. (follow the link for more information).
Then I worked on the frame of the UIImageView to adapt itself to the new dimension, in landscape or portrait.

-(IBAction)takePhoto:(id)sender {
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
        self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        self.imgPicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
    } else { 
        imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    }
    [self presentModalViewController:self.imgPicker animated:YES];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];

    NSDate *date = [NSDate date];
    NSString *photoName = [dateFormatter stringFromDate:date];    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUs    erDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", photoName]];

    UIImage *picture = [info objectForKey:UIImagePickerControllerOriginalImage];

    // ---------RESIZE CODE--------- //
    if (picture.size.width == 1936) {
        picture = [picture scaleToSize:CGSizeMake(480.0f, 720.0f)];
    } else {
        picture = [picture scaleToSize:CGSizeMake(720.0f, 480.0f)];
    }
    // --------END RESIZE CODE-------- //

    photoPreview.image =  picture;

    // ---------FRAME CODE--------- //
    photoPreview.contentMode = UIViewContentModeScaleAspectFit;
    CGRect frame = photoPreview.frame;
    if (picture.size.width == 480) {
        frame.size.width = 111.3;
        frame.size.height =167;
    } else {
        frame.size.width = 167;
        frame.size.height =111.3;
    }
    photoPreview.frame = frame;
    // --------END FRAME CODE-------- //


    NSData *webData = UIImagePNGRepresentation(picture);
    CGImageRelease([picture CGImage]);
    [webData writeToFile:imagePath atomically:YES];
    imgPicker = nil;
}

Now I have a new issue! If I take a picture in landscape, and try to take another one in portrait, the app crashs. Do I have to release something?

  • 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-05-26T07:30:35+00:00Added an answer on May 26, 2026 at 7:30 am

    I had the same issue, there is no edited image when using the camera, you must use the original image :

    originalimage = [editingInfo objectForKey:UIImagePickerControllerOriginalImage];
    
    if ([editingInfo objectForKey:UIImagePickerControllerMediaMetadata]) {
        // test to chek that the camera was used
        // especially I fund out htat you then have to rotate the photo
        ...
    

    If it was cropped when usign the album you have to re-crop it of course :

    if ([editingInfo objectForKey:UIImagePickerControllerCropRect] != nil) {
        CGRect cropRect = [[editingInfo objectForKey:UIImagePickerControllerCropRect] CGRectValue];
        CGImageRef imageRef = CGImageCreateWithImageInRect([originalimage CGImage], cropRect);
        chosenimage = [UIImage imageWithCGImage:imageRef]; 
        CGImageRelease(imageRef);
    } else {
        chosenimage = originalimage;
    }
    

    The croprect info is also present for the camera mode, you need to check how you want it to behave.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hii everyone! I have some text fields in each cell of the table view,
I have a View where some input text to be added dynamica using jquery,
I have an scroll view with some sophisticated animations happening during scrolling. Although after
When I have a table view with some sections which have their own headers
Into some view data i have put the result of an anonymous type: var
I have a view that I want to add some custom drawing to. I
I have a view where the user can change some settings, its basically a
I have a simple list view with some check boxes in an alert dialog.
I have a view using a master page that contains some javascript that needs
I have a view controller that gets presented modally and changes some data that

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.