views:

826

answers:

2

After I load an image from the device, I need to rotate it 37.8 degrees then display it on a View.

Is there an function in Objective-C that can do the image rotation?

Ian

+1  A: 

Yes, see my answer to this question: http://stackoverflow.com/questions/1999309/question-about-rotating-a-slider/1999389#1999389

To convert degrees to radians (for the positionInRadians arg) use this function:

CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
cidered
I need to rotate just the image though, not the view. Is that possible?
BahaiResearch.com
Can't you just load the image into a UIImageView and add it as a subview? Otherwise I see KennyTM has answered how to take a UIImage and rotate to get another UIImage.
cidered
+3  A: 

To rotate the view:

imageView.transform = CGAffineTransformMakeRotation(37.8°);

To rotate the image,

  1. Calculate the width and height will be occupied by the image after rotation.
  2. Create a CGContext by UIGraphicsBeginImageContext.
  3. CGContextRotateCTM(UIGraphicsGetCurrentContext(), 37.8°);
  4. [yourImage drawAtPoint:...];
  5. UIGraphicsGetImageFromCurrentImageContext(); and use this image instead.
  6. Release the context.
KennyTM
Nice Explanation. Thanks
Biranchi