Rotate Newly Created iOS Image 90 Degrees Prior to Saving as PNG

Viewed 7905

I have read numerous answers related to this, but I still can't get it to work.

I have a view where a user can sign their name. Here's how it looks: http://d.pr/i/McuE

I can successfully retrieve this image and save it to the file system, but I need to rotate it 90 degrees before saving so the signature reads from left-to-right.

// Grab the image
UIGraphicsBeginImageContext(self.signArea.bounds.size);
[self.signArea drawRect: self.signArea.bounds];
UIImage *signatureImage = UIGraphicsGetImageFromCurrentImageContext();

//-- ? -- Rotate the image (this doesn't work) -- ? --
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextRotateCTM(context, M_PI_2);

UIGraphicsEndImageContext();

//Save the image as a PNG in Documents folder
[UIImagePNGRepresentation(signatureImage) writeToFile:[[PPHelpers documentsPath] stringByAppendingPathComponent:@"signature-temp.png"] atomically:YES];

How can I rotate the image prior to saving?

Thanks in advance for your help. I'm on Xcode 5 using the iOS 7 SDK.

1 Answers
Related