我在繪製通過QTKit mCaptureDecompressedVideoOutput獲取的NSCIImageRep時遇到了問題。如何繪製NSCIImageRep到NSView
因爲我不想畫使用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是一個指向CGImageRef我通過mCaptureDecompressedVideoOutput回調獲得
- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection`.
此代碼崩潰我的機器。有什麼建議麼?
你可以從崩潰發佈堆棧跟蹤? – 2012-01-27 13:11:43