WFRecScreenDemo icon indicating copy to clipboard operation
WFRecScreenDemo copied to clipboard

感觉楼主提供了延时摄影的思路。

Open leewaycn opened this issue 5 years ago • 0 comments

感觉楼主提供了延时摄影的思路。

- (void)getFrame
{
    if (!_writing) {
        _writing = true;
        size_t width  = CGBitmapContextGetWidth(context);
        size_t height = CGBitmapContextGetHeight(context);
//        NSLog(@"width,height:(%ld ,%ld)",width,height);
        @try {
            CGContextClearRect(context, CGRectMake(0, 0,width , height));
            
//            [self.captureLayer renderInContext:context];
//            self.captureLayer.contents=nil;

            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                if (self.renderView) {
                    [self.renderView.layer renderInContext:context];
                    self.renderView.layer.contents = nil;
                }else{
                    
                    [[[UIApplication sharedApplication].delegate window].layer renderInContext:context];
                    [[UIApplication sharedApplication].delegate window].layer.contents = nil;
                }
                CGImageRef cgImage = CGBitmapContextCreateImage(context);
                
                if (_recording) {
                    float millisElapsed = [[NSDate date] timeIntervalSinceDate:startedAt] * 1000.0-_spaceDate*1000.0;
                    //NSLog(@"millisElapsed = %f",millisElapsed);
                    [self writeVideoFrameAtTime:CMTimeMake((int)millisElapsed, 1000) addImage:cgImage];
                }
                CGImageRelease(cgImage);
            });
          
        }
        @catch (NSException *exception) {
         
            NSLog(@"原来是这里出了问题:%@",exception);
        }
        _writing = false;
    }
}

上面这段代码是为了修正线程警告的问题。

leewaycn avatar Jul 29 '20 08:07 leewaycn