How to draw NSCIImageRep for NSView

I'm having problems drawing the NSCIImageRep that I get through QTKit mCaptureDecompressedVideoOutput.

Since I don't want to draw an image using OpenGL, I tried to subclass NSView and draw the image there:

- (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 is a pointer to a CGImageRef that I get through the mCaptureDecompressedVideoOutput callback

 - (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection`. 

This code crashes my car. Any suggestions?

+4
source share
1 answer

You do not need to go through CGImageRef just for drawing NSCIImageRep . Just ask him CIImage and draw this:

 CIImage* anImage = [yourNSCIImageRep CIImage]; [anImage drawAtPoint:NSZeroPoint fromRect:NSRectFromCGRect([anImage extent]) operation:NSCompositeSourceOver fraction:1.0]; 
+4
source

Source: https://habr.com/ru/post/1393357/


All Articles