Question

I am using an imagepicker in my app. It works perfectly for MOST images, however, it has trouble with images originally taken from the iPhone 4 camera (I think because they are so big). Pics from the iPhone 5 camera and screenshots all work fine. When uploading a pic originally taken from the iPhone 4 camera, the picker rotates them 90 degrees to the left. I think it is also related, but my app has a feature where the user can save images to their camera roll, and it works fine for most images, but the ones taken from the iPhone 4 camera that are rotated 90 degrees DO NOT save.

Here is my code:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if ([self.imagePicker isEqual:picker])
{
    //
    // Saving into Documents folder
    //
    NSString* path = [NSHomeDirectory() stringByAppendingString:@"/Documents/one.png"];

    BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path
                                                      contents:nil attributes:nil];

    if (!ok) {
        NSLog(@"Error creating file %@", path);
    } else {
        NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
        [myFileHandle writeData:UIImagePNGRepresentation(info [UIImagePickerControllerOriginalImage])];
        [myFileHandle closeFile];
    }

    //
    // Loading from documents
    //
    NSFileHandle* myFileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
    UIImage* loadedImage = [UIImage imageWithData:[myFileHandle readDataToEndOfFile]];
    self.chosenImageOne = loadedImage;
    [self.imageViewOne setImage:self.chosenImageOne];
    [self dismissViewControllerAnimated:YES completion:nil];
}
}
Was it helpful?

Solution

This question still shows up as unanswered but the issue/ issues were fixed by changing png representation to jpg.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top