Search code examples
objective-cmacosnsimageqtkit

Mirroring CIImage/NSImage


Currently I have the following

 CIImage *img = [CIImage imageWithCVImageBuffer: imageBuffer];

 NSCIImageRep *imageRep = [NSCIImageRep imageRepWithCIImage:img];
 NSImage *image = [[[NSImage alloc] initWithSize: [imageRep size]] autorelease];
 [image addRepresentation:imageRep];

This works perfectly, I can use the NSImage and when written to a file the image is exactly how I need it to be.

However, I'm pulling this image from the users iSight using QTKit, so I need to be able to flip this image across the y axis.

My first thought was to transform the CIImage using something like this, however my final image always comes out completely blank. When written to a file the dimensions are correct but it's seemingly empty.

- (CIImage *)flipImage:(CIImage *)image
{
    return [image imageByApplyingTransform:CGAffineTransformMakeScale(-1, 1)];
}

Am I approaching this the wrong way? Or have I made a mistake in my code?


Solution

  • That transform flips it, but the axis around which it flips is not at the center of the image, but at the left edge. You must also translate the image by its width to account for the movement caused during the scale.