Skip to content

Instantly share code, notes, and snippets.

View mjarvis's full-sized avatar

Malcolm Jarvis mjarvis

  • British Columbia
View GitHub Profile
@mjarvis
mjarvis / Arbitrary rotation of a CGImage
Created December 14, 2011 22:20 — forked from sburlot/Arbitrary rotation of a CGImage
Grayscale for CGContextClipToMask
- (CGImageRef)CGImageRotatedByAngle:(CGImageRef)imgRef angle:(CGFloat)angle
{
CGFloat angleInRadians = angle * (M_PI / 180);
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGRect imgRect = CGRectMake(0, 0, width, height);
CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform);