2014-01-13 1 views
3

Я хочу добавить изображения в видеокамеру в режиме реального времени, но их нужно только отображать, не нужно сохранять. Если я использую стандартную процедуру Core Image, она работает нормально, но мне нужна дополнительная частота кадров. Но если я раскомментирую этот код и прокомментирую следующий, это не так. OpenGLView просто UIView подкласс методомEAGLContext с фильтрами основных фильтров

+(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); 

Чего не хватает? Что я делаю неправильно? Большое спасибо.

ответ

3

Хорошо, наконец, я понял. Не забудьте поставить этот код в 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]; 
Смежные вопросы