我在绘制通过 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`.
此代码使我的机器崩溃。有什么建议么?
最佳答案
您不需要仅仅通过 CGImageRef
来绘制 NSCIImageRep
。只需要它提供一个 CIImage 并绘制它即可:
CIImage* anImage = [yourNSCIImageRep CIImage];
[anImage drawAtPoint:NSZeroPoint
fromRect:NSRectFromCGRect([anImage extent])
operation:NSCompositeSourceOver
fraction:1.0];
关于cocoa - 如何将 NSCIImageRep 绘制到 NSView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9033607/