gpt4 book ai didi

ios - uielementinput 未显示在 gpuimage 中

转载 作者:行者123 更新时间:2023-11-29 13:01:06 25 4
gpt4 key购买 nike

我正在尝试覆盖在 UIViewParticleEmitter 中实现的粒子发射器。

当我尝试将 UIView 添加为 uiElementInput 时,它没有显示。相机输入仍然有效,但粒子发射器未显示。

更新代码:

//ParticleEmitter source:

//=========================================================
// ParticleEmitter.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@interface ParticleEmitter : UIView{
CAEmitterLayer *emitter;
}
@end

//=========================================================
// ParticleEmitter.m

#import "ParticleEmitter.h"

@implementation ParticleEmitter

- (id)initWithFrame:(CGRect)frame

{
self = [super initWithFrame:frame];
if (self) {
// Initialization code

float multiplier = 0.25f;

CGPoint pt;
pt.x = (frame.origin.x+(frame.size.width/2));
pt.y = (frame.origin.y+frame.size.height/2);

//Create the emitter layer
emitter = [CAEmitterLayer layer];
emitter.emitterPosition = pt;
emitter.emitterMode = kCAEmitterLayerOutline;
emitter.emitterShape = kCAEmitterLayerCircle;
emitter.renderMode = kCAEmitterLayerAdditive;
emitter.emitterSize = CGSizeMake(100 * multiplier, 0);

//Create the emitter cell
CAEmitterCell* particle = [CAEmitterCell emitterCell];
particle.scale=0.05;
particle.emissionLongitude = M_PI;
particle.birthRate = multiplier * 100.0;
particle.lifetime = multiplier*30;
particle.lifetimeRange = multiplier * 4.0f;
particle.velocity = 300;
particle.velocityRange = 400;
particle.emissionRange = 5.5;
particle.scaleSpeed = 0.05; // was 0.3
particle.alphaRange = 0.02;
particle.alphaSpeed = 0.5;



//particle.color = [[COOKBOOK_PURPLE_COLOR colorWithAlphaComponent:0.5f] CGColor];
particle.contents = (__bridge id)([UIImage imageNamed:@"baloon.png"].CGImage);
particle.name = @"particle";

emitter.emitterCells = [NSArray arrayWithObject:particle];
[self.layer addSublayer:emitter];


[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
// emitter.emitterPosition = pt;
[CATransaction commit];



}


return self;

//=========================================== ============

//我想如何将粒子发射器与 GPUimage 一起使用:

         newfilter = [[GPUImageSepiaFilter alloc] init];

blendFilter = nil;


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


CGRect pviewFrame = CGRectMake(0, 0, 640, 480 );
UIView *pView = [[ParticleEmitter alloc] initWithFrame:pviewFrame];


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


[newfilter addTarget:blendFilter];
[uiElementInput addTarget:blendFilter];



__unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput;

[newfilter setFrameProcessingCompletionBlock:^(GPUImageOutput *newfilter, CMTime frameTime){
pView.alpha = 0.9;
[weakUIElementInput update];
}];


[newfilter addTarget:filterView];
[videoCamera addTarget:newfilter];

//=========================================== ============//FilterShowcase 中与文本一起使用的示例代码:

        newfilter = [[GPUImageSepiaFilter alloc] init];

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

NSDate *startTime = [NSDate date];

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

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

[newfilter addTarget:blendFilter];
[uiElementInput addTarget:blendFilter];


__unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput;

[newfilter setFrameProcessingCompletionBlock:^(GPUImageOutput * newfilter, CMTime frameTime){
timeLabel.text = [NSString stringWithFormat:@"Time: %f s", -[startTime timeIntervalSinceNow]];
[weakUIElementInput update];
}];

[newfilter addTarget:filterView];

[blendFilter addTarget:filterView];

[videoCamera addTarget:newfilter];

//=========================================== ============

有什么建议吗?

最佳答案

我认为没有办法将 CAEmitterLayer 与 GPUImageUIElement 一起使用。后者依赖于 -renderInContext: 来栅格化您传递给它的 UI 元素,以及一些 UI 元素,例如 CAEmitterLayer will not be rendered via this method .

不幸的是,没有其他方法可以向 OpenGL ES 提供这种内容,因此您需要找到除 CAEmitterLayer 之外的其他方法来生成粒子效果。

关于ios - uielementinput 未显示在 gpuimage 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19756287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com