AVAssetImageGenerator provides images rotated

前端 未结 3 1805
名媛妹妹
名媛妹妹 2020-12-08 06:29

When obtaining a UIImage of a video via AVAssetImageGenerator, I\'m getting back images rotated (well, technically they\'re not) when the video is shot in portrait orientati

3条回答
  •  天涯浪人
    2020-12-08 07:07

    The copy and paste solution to create image with the recording orientation using the previous answer.

    AVURLAsset* asset = [AVURLAsset URLAssetWithURL:url options:nil];
    AVAssetImageGenerator* imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
    imageGenerator.appliesPreferredTrackTransform = YES;
    CGImageRef cgImage = [imageGenerator copyCGImageAtTime:CMTimeMake(0, 1) actualTime:nil error:nil];
    UIImage* image = [UIImage imageWithCGImage:cgImage];
    
    CGImageRelease(cgImage);
    

提交回复
热议问题