第49月第16天 iOS CIImage 旋转

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 旋转

上一篇:139 Android 零基础入门 02 Java面向对象 07 Java多态 03 多态的实现(难点) 05 类型转换案例(上)


下一篇:iOS UItable view cell 左滑删除