0

This line of code has no effect. It does not change orientation of the image. What am I doing wrong?

// image is of type UIImage
UIImage * newImage = [UIImage imageWithCGImage:[image CGImage] scale:image.scale orientation:UIImageOrientationLeft];
Anne
  • 26,765
  • 9
  • 65
  • 71
kal21
  • 461
  • 5
  • 18
  • This answer will be usefull for you: http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload/5427890#5427890 It works fine. – kaspartus Nov 18 '11 at 06:44

1 Answers1

0

Refer to the definition of this method below, make sure your CGImage is of a CGImageRef class. imageWithCGImage:[image CGImage]

+(UIImage *)imageWithCGImage:(CGImageRef)imageRef scale:(CGFloat)scale orientation:(UIImageOrientation)orientation

Following three lines are some initializations before you call the method.

CIContext * context = [CIContext contextWithOptions:nil]; //your choice
CIImage * OriginalImage = [CIImage imageWithContentsOfURL:fileNameAndPath]; //your own choice of source image file.

CGImageRef CGImage = [context createCGImage:OriginalImage fromRect:(CGRect)];
UIImage *newImage = [UIImage imageWithCGImage:CGImage scale:1.0 orientation:UIImageOrientationLeft]

Hope this helps.

Ohmy
  • 2,201
  • 21
  • 24