美文网首页
[iOS] CMSampleBufferRef生成 UIImag

[iOS] CMSampleBufferRef生成 UIImag

作者: manajay | 来源:发表于2018-04-26 14:10 被阅读58次
    + (UIImage *)lj_imageFromBuffer:(CMSampleBufferRef)buffer {
        
        CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(buffer);
        
        CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
        
        CIContext *temporaryContext = [CIContext contextWithOptions:nil];
        CGImageRef videoImage = [temporaryContext createCGImage:ciImage fromRect:CGRectMake(0, 0, CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer))];
        
        UIImage *image = [UIImage imageWithCGImage:videoImage];
        CGImageRelease(videoImage);
        
        return image;
    }
    

    相关文章

      网友评论

          本文标题:[iOS] CMSampleBufferRef生成 UIImag

          本文链接:https://www.haomeiwen.com/subject/zlnplftx.html