Cut the image into small pieces (IOS)
Cut the image into small pieces (IOS)
# Import # Import
Int main (int argc, const char * argv []) {
@ Autoreleasepool {
If (argc <2 ){
Return 0;
}
NSString * inputFile = [NSString stringWithCString: argv [1] encoding: NSUTF8StringEncoding];
CGFloat titleSize = 256;
NSString * outputPath = [inputFile stringByDeletingPathExtension];
NSImage * image = [[NSImage alloc] initWithContentsOfFile: inputFile];
NSSize size = [image size];
NSArray * representations = [image representations];
If ([representations count]) {
NSBitmapImageRep * representation = representations [0];
Size. width = [representation pixelsWide];
Size. height = [representation pixelsHigh];
}
NSRect rect = NSMakeRect (0, 0, size. width, size. height );
CGImageRef imageRef = [image CGImageForProposedRect: & rect context: NULL hints: nil];
NSInteger rows = ceil (size. height/titleSize );
NSInteger cols = ceil (size. width/titleSize );
For (int y = 0; y For (int x = 0; x CGRect titleRect = CGRectMake (x * titleSize, y * titleSize, titleSize, titleSize );
CGImageRef titleImage = CGImageCreateWithImageInRect (imageRef, titleRect );
NSBitmapImageRep * imageRep = [[NSBitmapImageRep alloc] initWithCGImage: titleImage];
NSData * data = [imageRep representationUsingType: ns1_filetype properties: nil];
CGImageRelease (titleImage );
NSString * path = [outputPath stringByAppendingFormat: @ _ % 02i_%02i.jpg, x, y];
[Data writeToFile: path atomically: NO];
}
}
}
Return 0 ;}
Terminal run:./CutImageAPP 1.jpg