我正在尝试使用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];

最佳答案

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

10-02 09:17