我在绘制通过QTKit mCaptureDecompressedVideoOutput获取的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)
您无需通过CGImageRef
来绘制NSCIImageRep
。只需要它CIImage
并绘制:
CIImage* anImage = [yourNSCIImageRep CIImage];
[anImage drawAtPoint:NSZeroPoint
fromRect:NSRectFromCGRect([anImage extent])
operation:NSCompositeSourceOver
fraction:1.0];