简体   繁体   English

如何在iPhone的UIImagePickerController中捕获视频的缩略图

[英]how to capture the thumnail of the video in UIImagePickerController in iphone

I am capturing the thumnail of video it work fine but problem is that it capture the thumbnail in horizontal mode but i want in vertical mode any idea how to fix this issue. 我正在捕获视频的缩略图,但效果很好,但问题是它在水平模式下捕获了缩略图,但是我想在垂直模式下找到解决此问题的任何想法。

here is the code for thumbnail. 这是缩略图的代码。

    AVAsset *asset = [AVAsset assetWithURL:movieURL];// url= give your url video here
    AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
    CMTime time = CMTimeMake(1, 5);//it will create the thumbnail after the 5 sec of video 
    CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];
    UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
    thumbnailImageView.image=thumbnail;

Get rotated image using following code, and use final image 使用以下代码获取旋转的图像,并使用最终图像

UIGraphicsBeginImageContext(thumbnail.size);//thumbnail is your original image
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextRotateCTM (context, radians(90));//set rotation as per your requirement
[thumbnail drawAtPoint:CGPointMake(0, 0)];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();//image after rotation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM