-
-
Save yyjim/4dc3413f835f5f4b58b0d4d075fc05f6 to your computer and use it in GitHub Desktop.
Rotate CGImage 90 degree clock wise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void) rotate90Degree:(CGImageRef) cgImageRef | |
{ | |
int cgImageWidth = (int)CGImageGetWidth(cgImageRef); | |
int cgImageHeight = (int)CGImageGetHeight(cgImageRef); | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
NSUInteger bytesPerPixel = 4; | |
int targetWidth = cgImageHeight; | |
int targetHeight = cgImageWidth; | |
NSUInteger bytesPerRow = bytesPerPixel * targetWidth; | |
NSUInteger bitsPerComponent = 8; | |
CGContextRef context = CGBitmapContextCreate(nil, targetWidth, targetHeight, | |
bitsPerComponent, bytesPerRow, colorSpace, | |
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault); | |
CGContextRotateCTM (context, -M_PI_2); | |
CGContextTranslateCTM(context, -(int)targetHeight, 0); | |
CGContextDrawImage(context, CGRectMake(0, 0, cgImageWidth, cgImageHeight), cgImageRef); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment