第37月第29天 avplayer截屏

1.

- (void)displayLinkCallback:(CADisplayLink *) sender{
    CMTime time = [snapshotOutput itemTimeForHostTime:CACurrentMediaTime()];
    if ([snapshotOutput hasNewPixelBufferForItemTime:time]) {
        lastSnapshotPixelBuffer = [snapshotOutput copyPixelBufferForItemTime:time itemTimeForDisplay:NULL];
    }
}

- (UIImage *)snapshotImage {
    if (lastSnapshotPixelBuffer) {
        CIImage *ciImage = [CIImage imageWithCVPixelBuffer:lastSnapshotPixelBuffer];
        CIContext *context = [CIContext contextWithOptions:NULL];
        CGRect rect = CGRectMake(0,
                                 0,
                                 CVPixelBufferGetWidth(lastSnapshotPixelBuffer),
                                 CVPixelBufferGetHeight(lastSnapshotPixelBuffer));
        CGImageRef cgImage = [context createCGImage:ciImage fromRect:rect];
        return [UIImage imageWithCGImage:cgImage];
    }
    return NULL;
}

http://darktechlabs.com/2016/07/15/iOS-%E5%B0%8F%E5%9D%91%E8%AE%B0%E5%BD%95%EF%BC%9A%E5%A6%82%E4%BD%95%E7%BB%99-AVPlayer-%E6%88%AA%E5%9B%BE/

猜你喜欢

转载自www.cnblogs.com/javastart/p/11758849.html