我想将图像实时添加到相机视频源中,但只需要显示它们,无需保存。如果我使用标准核心图像程序,它可以正常工作,但我需要更高的帧速率。但是,如果我取消注释此代码并在下一个注释它不会。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);
什么不见了?我做错了什么?非常感谢。