2014-01-13 6 views
3

이미지를 실시간으로 카메라 비디오 피드에 추가하려고하지만 저장할 필요가 없으므로 저장할 필요가 없습니다. 표준 Core Image 절차를 사용하면 정상적으로 작동하지만 더 많은 프레임 속도가 필요합니다. 그러나이 코드의 주석을 제거하고 다음에 주석을 달지 않으면 그렇지 않습니다. OpenGLView코어 이미지 필터가있는 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); 

무엇 누락 방법

와 단지 UIView 서브 클래스? 내가 뭘 잘못하고 있니? 고맙습니다.

답변

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];