Created
December 10, 2013 15:51
-
-
Save adow/7892865 to your computer and use it in GitHub Desktop.
Split an image
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
///分割图片 | |
static inline NSArray* WKFlip_make_hsplit_images_for_image(UIImage* image){ | |
CGSize halfSize=CGSizeMake(image.size.width, image.size.height/2); | |
UIGraphicsBeginImageContext(halfSize); | |
CGContextRef context=UIGraphicsGetCurrentContext(); | |
CGContextSaveGState(context); | |
// Flip the coordinate system | |
CGContextSetTextMatrix(context, CGAffineTransformIdentity); // 2-1 | |
CGContextTranslateCTM(context, 0, halfSize.height); // 3-1 | |
CGContextScaleCTM(context, 1.0, -1.0); // 4-1 | |
CGImageRef imageRef=image.CGImage; | |
CGContextDrawImage(context, CGRectMake(0, -1*halfSize.height, | |
image.size.width, | |
image.size.height), | |
imageRef); | |
UIImage* imageFirst=UIGraphicsGetImageFromCurrentImageContext(); | |
CGContextClearRect(context, CGRectMake(0, 0, image.size.width , image.size.height)); | |
CGContextDrawImage(context, CGRectMake(0,0, | |
image.size.width, | |
image.size.height), | |
imageRef); | |
UIImage* imageSecond=UIGraphicsGetImageFromCurrentImageContext(); | |
CGContextRestoreGState(context); | |
UIGraphicsEndImageContext(); | |
//WLog_Float(@"hSplitImageToArray duration", CFAbsoluteTimeGetCurrent()-startTime); | |
return @[imageFirst,imageSecond,]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment