Screenshot for AVPlayer and Video

前端 未结 4 767
抹茶落季
抹茶落季 2020-11-30 00:13

I am trying to take a screenshot of an AVPlayer inside a bigger view. I want to build a testing framework only, so private APIs or any method is go

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 01:01

    If you want to take screenshot of current screen just call following method on any action event which give you Image object.

    -(UIImage *) screenshot
    {
        UIGraphicsBeginImageContext(self.view.bounds.size);
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *sourceImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        //now we will position the image, X/Y away from top left corner to get the portion we want
        UIGraphicsBeginImageContext(sourceImage.size);
        [sourceImage drawAtPoint:CGPointMake(0, 0)];
        UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        //To write image on divice.
        //UIImageWriteToSavedPhotosAlbum(croppedImage,nil, nil, nil);
    
        return croppedImage;
    }
    

    Hope this will help you.

提交回复
热议问题