镜像CIImage/NSImage [英] Mirroring CIImage/NSImage

查看:293
本文介绍了镜像CIImage/NSImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有以下内容

 CIImage *img = [CIImage imageWithCVImageBuffer: imageBuffer];

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

这非常好用,我可以使用NSImage,并且在将图像写入文件时,正是我所需要的.

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

但是,我正在使用QTKit从用户iSight提取此图像,因此我需要能够在y轴上翻转此图像.

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.

我的第一个想法是使用类似的方法来转换CIImage,但是我的最终图像总是完全空白.写入文件时,尺寸是正确的,但似乎是空的.

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.

这篇关于镜像CIImage/NSImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆