views:

60

answers:

1

I am trying to copy a uiimage (ultimately I am planning to blur the copy). Right now the copied image shows correctly in the simulator but ends up rotated 90 degrees when running on the device.

I am using the following to create acopy:

 CGImageRef cgImage = [sourceImage CGImage];

// Make a new image from the CG Reference UIImage *copyOfImage = [[UIImage alloc] initWithCGImage:cgImage];

The source image is coming from a UIImagePickerController. The same results happen whether I grab the soruce from the library or the camera.

Thanks in advance for any help

A: 

According to documentation for UIImage, imageOrientation property contain the orientation for a image and it defaults to UIImageOrientationUp. But if the image have any EXIF data for orientation it will return that instead.

imageWithCGImage:(CGImageRef)cgImage and initWithCGImage:(CGImageRef)CGImage (in UIImage) will both default to UIImageOrientationUp orientation, which might be wrong if the image/movie actually was shot in e.g. landscape mode.

But if you use the versions of above that takes orientation as well and pass in sourceImage.imageOrientation it should work.

dlundqvist