首页 > 移动平台 > 详细

第49月第16天 iOS CIImage 旋转

时间:2020-10-16 11:09:49      阅读:107      评论:0      收藏:0      [点我收藏+]

1.

- (void)dealWithSampleBuffer:(CMSampleBufferRef)buffer {
    CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(buffer);
    
    CIImage *ciimage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
    size_t width                        = CVPixelBufferGetWidth(pixelBuffer);
    size_t height                       = CVPixelBufferGetHeight(pixelBuffer);
   // 旋转的方法
    CIImage *wImage = [ciimage imageByApplyingCGOrientation:kCGImagePropertyOrientationLeft];
    
    CIImage *newImage = [wImage imageByApplyingTransform:CGAffineTransformMakeScale(0.5, 0.5)];
    CVPixelBufferLockBaseAddress(pixelBuffer, 0);
    CVPixelBufferRef newPixcelBuffer = nil;
    CVPixelBufferCreate(kCFAllocatorDefault, height * 0.5, width * 0.5, kCVPixelFormatType_32BGRA, nil, &newPixcelBuffer);
    [_ciContext render:newImage toCVPixelBuffer:newPixcelBuffer];
    
    
    //
    CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
    CMVideoFormatDescriptionRef videoInfo = nil;
    CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, newPixcelBuffer, &videoInfo);
    CMTime duration = CMSampleBufferGetDuration(buffer);
    CMTime presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(buffer);
    CMTime decodeTimeStamp = CMSampleBufferGetDecodeTimeStamp(buffer);
    CMSampleTimingInfo sampleTimingInfo;
    sampleTimingInfo.duration = duration;
    sampleTimingInfo.presentationTimeStamp = presentationTimeStamp;
    sampleTimingInfo.decodeTimeStamp = decodeTimeStamp;
    //
    CMSampleBufferRef newSampleBuffer = nil;
    CMSampleBufferCreateForImageBuffer(kCFAllocatorMalloc, newPixcelBuffer, true, nil, nil, videoInfo, &sampleTimingInfo, &newSampleBuffer);
    
   // 对新buffer做处理
    
    // release
    CVPixelBufferRelease(newPixcelBuffer);
    CFRelease(newSampleBuffer);
}

 

https://www.jianshu.com/p/205083b93c1c

 

第49月第16天 iOS CIImage 旋转

原文:https://www.cnblogs.com/javastart/p/13824600.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!