GPUImage绿屏

时间:2012-12-20 02:54:55

标签: ios gpuimage

我正在尝试使用GPUImage进行绿屏效果。我试图实现的效果是播放一个窗帘电影,并用图像替换电影的白色部分。这将显示窗帘,然后窗帘打开以显示图像。

我正确显示电影,电影的白色部分为黑色但窗帘打开时图像不显示。有人可以看看下面的代码并告诉我我做错了吗?

提前致谢。格雷格

NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:@"CurtainsOpening" withExtension:@"m4v"];

GPUImageMovie *movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL];

movieFile.playAtActualSpeed = YES;

NSLog(@"movie file = %@", movieFile);

GPUImageChromaKeyBlendFilter *filter = [[GPUImageChromaKeyBlendFilter alloc] init];
[(GPUImageChromaKeyBlendFilter *)filter setColorToReplaceRed:1.0 green:1.0 blue:1.0];
[(GPUImageChromaKeyBlendFilter *)filter setThresholdSensitivity:0.0]; //was 0.4

[movieFile addTarget:filter];

UIImage *inputImage = [UIImage imageNamed:@"curtains.jpg"];
NSLog(@"inputImage = %@", inputImage);
GPUImagePicture *overlayPicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];

NSLog(@"overlayPicture = %@", overlayPicture);

[overlayPicture processImage];
[overlayPicture addTarget:filter];
//[movieFile addTarget:overlayPicture];

GPUImageView *view0 = [[GPUImageView alloc] initWithFrame:self.view.frame];
[view0 setFillMode:kGPUImageFillModeStretch];

NSLog(@"view0 = %@", view0);
[filter addTarget:view0];

[self.view addSubview:view0];

[view0 bringSubviewToFront:self.view];

NSLog(@"frame = %f %f", self.view.frame.size.width, self.view.frame.size.height);

[movieFile startProcessing];

1 个答案:

答案 0 :(得分:3)

我弄明白了。如果有人想知道您需要将GPUImagePicture变量设为实例变量,那么代码在退出方法时不会从内存中删除该变量。