我在绘制通过QTKit mCaptureDecompressedVideoOutput获得的NSCI
ImageRep时遇到了麻烦.
由于我不想使用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`.
这段代码崩溃了我的机器.有什么建议?
解决方法
您不需要通过CGImageRef来绘制NSCIImageRep.只要问它CIImage并绘制:
CIImage* anImage = [yourNSCIImageRep CIImage]; [anImage drawAtPoint:NSZeroPoint fromRect:NSRectFromCGRect([anImage extent]) operation:NSCompositeSourceOver fraction:1.0];