2012-01-27 6 views
4

QTKit mCaptureDecompressedVideoOutput을 통해 얻은 NSCIImageRep을 그리는 데 문제가 있습니다. NSView에 NSCIImageRep을 그리는 방법

내가 OpenGL을 사용하여 이미지를 그리려하지 않는

, 나는 NSView의 서브 클래스 거기 이미지를 그리는 시도 :

- (void) drawRect:(NSRect)dirtyRect 
{ 
    NSLog(@"DrawInRect"); 
    CGContextRef myContext = [[NSGraphicsContext currentContext] graphicsPort]; 

    if (imageRep != nil) 
    { 
     CGImageRef image = [imageRep CGImageForProposedRect: &dirtyRect context: [NSGraphicsContext currentContext] hints:nil]; 
     CGContextDrawImage(myContext, dirtyRect, image); 
     CGImageRelease(image); 
    } 
} 

imageRep 내가 mCaptureDecompressedVideoOutput 콜백을 통해 얻으 CGImageRef에 대한 포인터입니다

- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection`. 

이 코드는 내 컴퓨터를 고장납니다. 어떤 제안?

+0

당신이 충돌에서 스택 추적을 게시 할 수 있습니까? –

답변

4

NSCIImageRep을 그리기 위해 CGImageRef을 사용할 필요는 없습니다. 그냥 CIImage을 위해 그것을 요구하고 그릴 :

CIImage* anImage = [yourNSCIImageRep CIImage]; 
[anImage drawAtPoint:NSZeroPoint 
      fromRect:NSRectFromCGRect([anImage extent]) 
      operation:NSCompositeSourceOver 
      fraction:1.0]; 
+1

네, 결국 알게되었습니다. 나는 실제로 그것을 NSImage로 변환하려고 시도했지만 그로 인해 그림을 그릴 때 알 수없는 메모리 누수가 발생했습니다. – Koffiman