Convert UIView Layer to UIImage

后端 未结 7 1561
深忆病人
深忆病人 2020-12-29 10:34

I\'m playing Video using AVPlayerLayer in a View. I need to convert View to Image, I tried

[myview.layer renderInContext:context];

but thi

7条回答
  •  没有蜡笔的小新
    2020-12-29 11:11

    The MPMoviePlayerController makes it easy to get a image from a movie at a certain point in the movie.

        - (UIImage*)imageFromVideoAtPath:(NSString *)path atTime:(NSTimeInterval)time {
        NSURL *videoURL = [NSURL fileURLWithPath:path];
        MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
        [moviePlayer prepareToPlay];
        UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:time timeOption:MPMovieTimeOptionNearestKeyFrame];
        [moviePlayer stop];
        return thumbnail;
    }
    

    Just call this with the path of the video, and at the time you want to get the image.

提交回复
热议问题