tags:

views:

257

answers:

1

Hi,

In my application I m using following codes to crop the captured image :-

-(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{   
#ifdef _DEBUG
    NSLog(@"frmSkinImage-imagePickerController-Start");
#endif

    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    //=======================================
    UIImage *image =imageView.image;
    CGRect cropRect = CGRectMake(100, 100, 125,128);
    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);
    [imageView setImage:[UIImage imageWithCGImage:imageRef]]; 
    CGImageRelease(imageRef);
    //===================================================
    //imgglobal = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    // for saving image to photo album
    //UIImageWriteToSavedPhotosAlbum(imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), self);
    [picker dismissModalViewControllerAnimated:YES];

#ifdef _DEBUG
    NSLog(@"frmSkinImage-imagePickerController-End");
#endif
}

But my problem is that when I use camera to take photo to crop the captured image it rotates the image to 90 degree towards right and in case I use Photo library it works perfectly.

So Can u filter my above codes to know where I m wrong.

Please help me out its urgent Thanks In Advance

+1  A: 

The CGImage is a UIImage without the meta data, and therefore loses the orientation information. I'd suggest that you get the orientation of the original [UIImage imageOrientation], store it and then apply it to the final image.

If that doesn't work, try applying a CGAffineTransformMakeRotation(90.0*0.0174532925); to the final image according to the orientation of the original.

Andiih