0

i'm trying to manage image rotation in imagePickerController:didFinishPickingMediaWithInfo, but after several attempts, I did not find any solutions. My last try is:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

        // load the storyboard by name
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[ApplicationSupport getStoryBoardName] bundle:nil];
        UploadViewController *uploadView = [storyboard instantiateViewControllerWithIdentifier:@"ViewUploadFile"];

        UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
        NSDictionary *metadataImage = [info valueForKey:UIImagePickerControllerMediaMetadata];

        uploadView.imageToUpload = image;

        if([[metadataImage objectForKey:@"Orientation"] intValue] == 3) {
            UIImage *imageRotated = [UIImage imageWithCGImage:[image CGImage] scale:[image scale] orientation:UIImageOrientationDown];
            uploadView.dataToUpload = UIImagePNGRepresentation(imageRotated);
        } else {
            uploadView.dataToUpload = UIImagePNGRepresentation(image);
        }

        // ETC...
    }

I can't and I don't want to use JPEGRepresentation. I need to rotate my photo by 180° when iPad is in specific position.

Any idea?

ApheX
  • 685
  • 2
  • 10
  • 26
  • have you tried using UIImageOrientationLeft or UIImageOrientationRight instead of Dowm. does it rotate? – Bonnie May 07 '13 at 08:45
  • After several attemps, i understood that i don't want to change an orientation "flag". I need to "physically" rotate my image. So i tried this: `UIGraphicsBeginImageContext(image.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextRotateCTM(context, (90 * M_PI / 180)); [image drawAtPoint:CGPointMake(0, 0)]; UIImage *imageRotated = UIGraphicsGetImageFromCurrentImageContext(); uploadView.dataToUpload = UIImagePNGRepresentation(imageRotated);` But it return to me blank image... – ApheX May 07 '13 at 09:21

2 Answers2

1

have a Look at this: http://www.catamount.com/blog/1015/uiimage-extensions-for-cutting-scaling-and-rotating-uiimages/

Just call

UIImage *rotatedImage = [originalImage imageRotatedByDegrees:180.0];

Source

Community
  • 1
  • 1
Bonnie
  • 4,943
  • 30
  • 34
0

UploadView.DataToUpload = [UIImage imageWithCGImage:[image CGImage] scale:1.0 orientation : UIImageOrientationDown];

For 180 deg rotation.

BonD
  • 39
  • 3