Nearest Neighbor Image Unit
I originally wrote this as an application using NSImage (with NSImageInterpolationNone), but decided to rewrite it as an Image Unit. So, here it is.
I originally wrote this as an application using NSImage (with NSImageInterpolationNone), but decided to rewrite it as an Image Unit. So, here it is.
July 9th, 2010 at 13:27:06
Another way to do this is with CIPixellate:
http://lists.apple.com/archives/quartz-dev/2009/Aug/msg00009.html
July 9th, 2010 at 16:34:16
Gus Mueller: I just tried it. It doesn’t work: The output is no different.
This makes sense, since filters only affect the inputs to other filters, not the other filters themselves. CIPixellate(scale=1.0) + CIAffineTransform(scale=x) doesn’t make the latter a nearest-neighbor scale; the latter does the same thing it would have done without the CIPixellate, with (since the CIPixellate has the identity scale) the same input image.
July 11th, 2010 at 10:14:43
Works for me:
CIFilter * scaler = [CIFilter filterWithName:@"CIPixellate"]; [scaler setDefaults]; [scaler setValue:[NSNumber numberWithFloat:1] forKey:@"inputScale"]; [scaler setValue:img forKey:@"inputImage"]; img = [scaler valueForKey:@"outputImage"]; CIFilter *f = [CIFilter filterWithName:@"CIAffineTransform"]; NSAffineTransform *t = [NSAffineTransform transform]; [t scaleXBy:_scale yBy:_scale]; [f setValue:t forKey:@"inputTransform"]; [f setValue:img forKey:@"inputImage"]; img = [f valueForKey:@"outputImage"];