CIAffineTile 程式碼例項
阿新 • • 發佈:2018-11-29
macOS
1.
NSString *sourceImagePath = [[NSBundle mainBundle] pathForResource:@"20" ofType:@"jpg"]; CIImage *sourceImg = [CIImage imageWithData:[NSData dataWithContentsOfFile:sourceImagePath]]; CGFloat pictureWidth = sourceImg.extent.size.width; CGFloat pictureHeight = sourceImg.extent.size.height; CGAffineTransform xform = CGAffineTransformIdentity; NSValue *xformObj = [NSValue valueWithBytes:&xform objCType:@encode(CGAffineTransform)]; CIImage *affineImage = [sourceImg imageByApplyingFilter:@"CIAffineTile" withInputParameters:@{kCIInputTransformKey : xformObj}]; CIImage *resut = [affineImage imageByCroppingToRect:CGRectMake(0,0, 2*pictureWidth, 2*pictureHeight)];
2.
NSString *sourceImagePath = [[NSBundle mainBundle] pathForResource:@"20" ofType:@"jpg"]; CIImage *sourceImg = [CIImage imageWithData:[NSData dataWithContentsOfFile:sourceImagePath]]; CGFloat pictureWidth = sourceImg.extent.size.width; CGFloat pictureHeight = sourceImg.extent.size.height; CIFilter *filterTile = [CIFilter filterWithName:@"CIAffineTile"]; [filterTile setDefaults]; [filterTile setValue:sourceImg forKey:kCIInputImageKey]; CGAffineTransform translate = CGAffineTransformMakeTranslation(pictureWidth, pictureHeight); [filterTile setValue:[NSValue valueWithBytes:&translate objCType:@encode(CGAffineTransform)] forKey:@"inputTransform"]; CIImage *affineImage = [filterTile outputImage]; CIVector *cropRect =[CIVector vectorWithX:0 Y:0 Z:2 * pictureWidth W:2 * pictureHeight]; CIFilter *crop = [CIFilter filterWithName:@"CICrop"]; [crop setValue:[filterTile outputImage] forKey:@"inputImage"]; [crop setValue:cropRect forKey:@"inputRectangle"]; CIImage *resut = [crop outputImage];