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?

有帮助吗?

解决方案

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.

其他提示

Here is some code that may help someone out ==>

    CGAffineTransform rotTrans = CGAffineTransformMakeRotation(M_PI_2);
    CGAffineTransform transTrans1 = CGAffineTransformTranslate(rotTrans, 0.0f, 320.0f);
    CGAffineTransform scaleTrans = CGAffineTransformScale(transTrans1, 1.0, -1.0);
    CGAffineTransform transTrans2 = CGAffineTransformTranslate(scaleTrans, -0.0f, -320.0f);

    self.view.transform = transTrans2;

I use it to flip frames from the front camera horizontally so they always appear up no matter what the rotation of the device. This stuff does get kind of tricky. One thing to do to help figure out what is going on is scaling down along either of the axes and seeing what the result is.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top