3

我想将图像实时添加到相机视频源中,但只需要显示它们,无需保存。如果我使用标准核心图像程序,它可以正常工作,但我需要更高的帧速率。但是,如果我取消注释此代码并在下一个注释它不会。OpenGLView只是一个UIView带有方法的子类

+(Class)layerClass {
return [CAEAGLLayer class];
}

//Working code
EAGLContext *myEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
NSDictionary *options = @{ kCIContextWorkingColorSpace : [NSNull null] };
CIContext *context = [CIContext contextWithEAGLContext:myEAGLContext options:options];
UIImage* foto = [UIImage imageNamed:@"foto2.jpg"];
UIImage* foto2 = [UIImage imageNamed:@"foto_no_ok.png"];
CIImage *backgroundImage = [[CIImage alloc]initWithImage:foto];
CIImage *foregroundImage = [[CIImage alloc]initWithImage:foto2];
 CIFilter *myFilter = [CIFilter filterWithName:@"CISourceOverCompositing" keysAndValues: kCIInputImageKey, foregroundImage, kCIInputBackgroundImageKey, backgroundImage, nil];
CIImage* resultingImage = [myFilter outputImage];

/* Not working code, GPU processing
self.view = [[OpenGLView alloc]initWithFrame:self.view.frame];
[self.view setOpaque:YES];
[self.view setFrame:CGRectMake(0, 0, 500, 500)];
[context drawImage:resultingImage inRect:self.view.bounds fromRect:self.view.bounds];
 */

//Working code, CPU processing
CGRect extent = [resultingImage extent];
CGImageRef cgImage = [context createCGImage:resultingImage fromRect:extent];
UIImage* myImage = [[UIImage alloc]initWithCGImage:cgImage];
self.myImageView.image = myImage;
CFRelease(cgImage);

什么不见​​了?我做错了什么?非常感谢。

4

1 回答 1

4

好的,最后我想通了。记住不要把这段代码放在viewDidLoad:. 图像需要一些工作,但这是一个不同的主题。

EAGLContext *myEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
NSDictionary *options = @{ kCIContextWorkingColorSpace : [NSNull null] };
self.context = [CIContext contextWithEAGLContext:myEAGLContext options:options];
[EAGLContext setCurrentContext:myEAGLContext];
self.visorOpenGLView.context = myEAGLContext;

UIImage* foto = [UIImage imageNamed:@"onepic.jpg"];
UIImage* foto2 = [UIImage imageNamed:@"anotherpic.png"];
CIImage *backgroundImage = [[CIImage alloc]initWithImage:foto];
CIImage *foregroundImage = [[CIImage alloc]initWithImage:foto2];
CIFilter *myFilter = [CIFilter filterWithName:@"CISourceOverCompositing" keysAndValues: kCIInputImageKey, foregroundImage, kCIInputBackgroundImageKey, backgroundImage, nil];
self.resultingImage = [myFilter outputImage];
UIImage* result = [UIImage imageWithCIImage:self.resultingImage];
self.resultingImageView.image = result;

CGRect ext = [foregroundImage extent];
[self.visorOpenGLView bindDrawable];
[self.context drawImage:self.resultingImage inRect:self.visorOpenGLView.frame fromRect:ext];
[self.visorOpenGLView display];
于 2014-01-15T17:24:27.000 回答