Implementation code of IOS video screenshot developed by IOS


Implementation code of IOS video screenshot developed by IOS

Now there are many video screenshots software. Here is a method of IOS video screenshots, which you can refer to,

Implementation code:

static int i=0; 
  UIGraphicsBeginImageContextWithOptions(CGSizeMake(640, 960), YES, 0); 
  [[self.window layer] renderInContext:UIGraphicsGetCurrentContext()]; 
  UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
  CGImageRef imageRef = viewImage.CGImage; 
  CGRect rect =CGRectMake(166, 211, 426, 320);// Here you can set the area where you want to take a screenshot 
  CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect); 
  UIImage *sendImage = [[UIImage alloc] initWithCGImage:imageRefRect]; 
  UIImageWriteToSavedPhotosAlbum(sendImage, nil, nil, nil);// Save pictures to photo gallery 
  NSData *imageViewData = UIImagePNGRepresentation(sendImage); 
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
  NSString *documentsDirectory = [paths objectAtIndex:0]; 
  NSString *pictureName= [NSString stringWithFormat:@"screenShow_%d.png",i]; 
  NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:pictureName]; 
  NSLog(@"%@", savedImagePath); 
  [imageViewData writeToFile:savedImagePath atomically:YES];// Save photos to sandbox directory 

Thank you for reading, hope to help you, thank you for your support to this site!