There are many ways to cut and cut an image, but here is one. It uses quartz to cut an image into 9 fractions of equal size. Please note that it does not process rotated images (this means images with the image Orientation! = 0), but it should start with you:
+(NSArray *)splitImageInTo9:(UIImage *)im{ CGSize size = [im size]; NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:9]; for (int i=0;i<3;i++){ for (int j=0;j<3;j++){ CGRect portion = CGRectMake(i * size.width/3.0, j * size.height/3.0, size.width/3.0, size.height/3.0); UIGraphicsBeginImageContext(portion.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextScaleCTM(context, 1.0, -1.0); CGContextTranslateCTM(context, 0, -portion.size.height); CGContextTranslateCTM(context, -portion.origin.x, -portion.origin.y); CGContextDrawImage(context,CGRectMake(0.0, 0.0,size.width, size.height), im.CGImage); [arr addObject:UIGraphicsGetImageFromCurrentImageContext()]; UIGraphicsEndImageContext(); } } return [arr autorelease]; }
The output will be an array of 9 images of each size (s / 3, height / 3)
fsaint
source share