cocoa – 如何将NSCIImageRep绘制到NSView

cocoa – 如何将NSCIImageRep绘制到NSView,第1张

概述我在绘制通过QTKit mCaptureDecompressedVideoOutput获得的NSCI ImageRep时遇到了麻烦. 由于我不想使用OpenGL绘制图像,我试图将NSView子类化并在那里绘制图像: - (void) drawRect:(NSRect)dirtyRect{ NSLog(@"DrawInRect"); CGContextRef myContext = 我在绘制通过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];
总结

以上是内存溢出为你收集整理的cocoa – 如何将NSCIImageRep绘制到NSView全部内容,希望文章能够帮你解决cocoa – 如何将NSCIImageRep绘制到NSView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1001191.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存