Objective-C 中框架的水平翻转
我正在尝试为我的程序(流式传输网络摄像头)创建一个过滤器,使框架水平翻转,使网络摄像头充当镜子。
然而,当它编译并运行时,过滤器似乎对它没有任何影响。
代码如下:
CIImage *resultImage = image;
CIFilter *flipFilter = [CIFilter filterWithName:@"CIAffineTransform"];
[flipFilter setValue:resultImage forKey:@"inputTransform"];
NSAffineTransform* flipTransform = [NSAffineTransform transform];
[flipTransform scaleXBy:-1.0 yBy:1.0]; //horizontal flip
[flipFilter setValue:flipTransform forKey:@"inputTransform"];
resultImage = [flipFilter valueForKey:@"outputImage"];
奇怪的是,其他过滤器似乎也能工作。例如:
CIFilter * ciEffectFilter = [CIFilter filterWithName:@"CIGloom"];
[ciEffectFilter setDefaults];
CIImage *resultImage = image;
[ciEffectFilter setValue: resultImage forKey:@"inputImage"];
[ciEffectFilter setValue:[NSNumber numberWithFloat: 0.75]
forKey:@"inputIntensity"];
[ciEffectFilter setValue:[NSNumber numberWithFloat: 20]
forKey:@"inputRadius"];
resultImage = [ciEffectFilter valueForKey:@"outputImage"];
CIFilter *ciCropFilter = [CIFilter filterWithName:@"CICrop"];
[ciCropFilter setDefaults];
[ciCropFilter setValue: resultImage forKey:@"inputImage"];
[ciCropFilter setValue: [CIVector vectorWithX:50 Y:50 Z:300 W:
300] forKey:@"inputRectangle"];
resultImage = [ciCropFilter valueForKey:@"outputImage"];
这与 NSAffineTransform 有关吗?我环顾四周,但没有找到任何答案。 多谢多谢!
I am trying to create a filter for my program (which streams a webcam) which makes the frame flip horizontally, making the webcam act like a mirror.
However, while it compiles and runs, the filter does not seem to have any effect on it.
Here is the code:
CIImage *resultImage = image;
CIFilter *flipFilter = [CIFilter filterWithName:@"CIAffineTransform"];
[flipFilter setValue:resultImage forKey:@"inputTransform"];
NSAffineTransform* flipTransform = [NSAffineTransform transform];
[flipTransform scaleXBy:-1.0 yBy:1.0]; //horizontal flip
[flipFilter setValue:flipTransform forKey:@"inputTransform"];
resultImage = [flipFilter valueForKey:@"outputImage"];
Strangely enough, other filters appear to work. For example:
CIFilter * ciEffectFilter = [CIFilter filterWithName:@"CIGloom"];
[ciEffectFilter setDefaults];
CIImage *resultImage = image;
[ciEffectFilter setValue: resultImage forKey:@"inputImage"];
[ciEffectFilter setValue:[NSNumber numberWithFloat: 0.75]
forKey:@"inputIntensity"];
[ciEffectFilter setValue:[NSNumber numberWithFloat: 20]
forKey:@"inputRadius"];
resultImage = [ciEffectFilter valueForKey:@"outputImage"];
CIFilter *ciCropFilter = [CIFilter filterWithName:@"CICrop"];
[ciCropFilter setDefaults];
[ciCropFilter setValue: resultImage forKey:@"inputImage"];
[ciCropFilter setValue: [CIVector vectorWithX:50 Y:50 Z:300 W:
300] forKey:@"inputRectangle"];
resultImage = [ciCropFilter valueForKey:@"outputImage"];
Is it something to do with NSAffineTransform? I have looked around, but I have not found any answers.
Thanks heaps!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定这是否是问题所在,但是在您的第一个代码片段中,您为同一个键设置了两个不同的值(您设置了 inputTransform 两次),我认为第一个应该是>inputImage 相反。请尝试以下操作:
此外,您可能需要将 X 轴平移图像的宽度
I'm not sure if this is the problem, but in your first code snippet you are setting two different values for the same key (you set
inputTransform
twice), I think the first one should beinputImage
instead. Try the following instead:Also, you may need to translate the X axis by the width of the image
您没有分配 CIImage Object 。
试试这个代码。
You are not Allocating CIImage Object .
Try This code.