【问题标题】:Text overlay not showing in GPUImage iOSGPUImage iOS中未显示文本覆盖
【发布时间】:2016-07-09 21:17:30
【问题描述】:

我正在尝试在视频上叠加一些文字,但到目前为止还没有成功。

videoCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0, 0, 1, 1)];
mCurrentImage = [UIImage imageNamed:@"tex16"];
sourcePicture = [[GPUImagePicture alloc] initWithImage:mCurrentImage smoothlyScaleOutput:NO];
[sourcePicture processImage];

customFilter = [[GPUFilter alloc] initWithFragmentShaderFromFile:@"shader"];
[videoCamera addTarget:cropFilter];
[cropFilter addTarget:customFilter atTextureLocation:0];
[sourcePicture addTarget:customFilter atTextureLocation:1];
[customFilter addTarget:mViewCameraPreview];//(GPUImageView*)mViewCameraPreview];

blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
blendFilter.mix = 1.0;

UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 240.0f, 320.0f)];
timeLabel.font = [UIFont systemFontOfSize:17.0f];
timeLabel.text = @"Time: 0.0 s";
timeLabel.textAlignment = NSTextAlignmentCenter;
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.textColor = [UIColor whiteColor];

uiElementInput = [[GPUImageUIElement alloc] initWithView:timeLabel];

[customFilter addTarget:blendFilter];
[uiElementInput addTarget:blendFilter];
[blendFilter addTarget:mViewCameraPreview];

[videoCamera startCameraCapture];

一切都符合并运行,没有抛出任何异常,但是找不到任何文本。

有人看到我做错了吗?

谢谢。

【问题讨论】:

  • cropFilter 太小。它是 1x1。 CGRectMake(0, 0, 1, 1)。

标签: ios objective-c gpuimage


【解决方案1】:

您是否尝试在开始相机捕捉后立即执行UIElementInput 的更新?如果没有,请尝试在您提供的代码末尾添加此代码。

__unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput;
[filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){
    [weakUIElementInput update];
}];

如果它不起作用或者您已经这样做了,您应该尝试使用基本过滤器(没有自定义过滤器)来查看问题是否仍然存在。

【讨论】:

    猜你喜欢
    • 2016-06-26
    • 1970-01-01
    • 2016-03-21
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 2022-11-30
    相关资源
    最近更新 更多