文字叠加层未在GPUImage iOS中显示 [英] Text overlay not showing in GPUImage iOS
问题描述
我正在尝试在视频上叠加一些文本,但到目前为止还没有成功.
I am trying to overlay some text on a video and have not had any success so far.
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];
所有内容都能正常运行,并且不会引发任何异常,但是找不到任何文本.
Everything complies and runs without throwing any exceptions, however there is no text to be found.
有人看到我在做什么错吗?
Does anyone see what I am doing wrong?
谢谢.
推荐答案
您是否尝试在开始捕获相机后立即执行UIElementInput
的更新?如果没有,请尝试在提供的代码末尾添加此代码.
Did you try performing an update of UIElementInput
right after starting camera capture ? If not, please try to add this code at the end of the code you provided.
__unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput;
[filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){
[weakUIElementInput update];
}];
如果它不起作用或已经完成,则应尝试使用基本过滤器(无自定义过滤器)以查看问题是否仍然存在.
If it doesn't work or if you've already did it, you should try with a basic filter (no custom filter) to see if the problem persists.
这篇关于文字叠加层未在GPUImage iOS中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!