Heim > Fragen und Antworten > Hauptteil
怪我咯2017-04-18 09:59:23
这是我用来获取截图的方法:
+(UIImage *)thumbnailOfAVAsset:(AVURLAsset *)asset {
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(0, 2);
CGImageRef oneRef = [generator copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *one = [UIImage imageWithCGImage:oneRef];// [[UIImage alloc] initWithCGImage:oneRef];
return one;
}
这个获取截图的方法最好不要在主线程中执行。
NSURL *url = [NSURL fileURLWithPath:path];//视频地址
AVURLAsset *asset = [AVURLAsset assetWithURL:url];
UIImage *thumbnailImage = [Class thumbnailOfAVAsset:asset];