本文介绍了AVAssetImageGenerator提供旋转的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当通过AVAssetImageGenerator获取视频的UIImage时,当视频以纵向方向拍摄时,我会返回旋转的图像(技术上它们不是)。如何判断视频的拍摄方向,然后正确旋转图像?
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 orientation. How can I tell what orientation the video was shot and then rotate the image properly?
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
NSError *err = NULL;
CMTime time = CMTimeMake(0, 60);
CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
[generate release];
UIImage *currentImg = [[UIImage alloc] initWithCGImage:imgRef];
推荐答案
最简单的方法是设置<$ c图像生成器上的$ c> applyPreferredTrackTransform 属性为YES,然后它会自动为您进行转换。
The easiest way is to just set the appliesPreferredTrackTransform
property on the image generator to YES, then it should automatically do the transformation for you.
这篇关于AVAssetImageGenerator提供旋转的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!