你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS 開發之ios視頻截屏的實現代碼

IOS 開發之ios視頻截屏的實現代碼

編輯:IOS開發綜合

IOS 開發之ios視頻截屏的實現代碼

           現在好多視頻截屏軟件,這裡提供一個IOS 視頻截屏的方法,大家可以參考下,

實現代碼:

//截屏 
static int i=0; 
-(IBAction)screenShot:(id)sender{ 
   
  UIGraphicsBeginImageContextWithOptions(CGSizeMake(640, 960), YES, 0); 
  [[self.window layer] renderInContext:UIGraphicsGetCurrentContext()]; 
  UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
  UIGraphicsEndImageContext(); 
  CGImageRef imageRef = viewImage.CGImage; 
  CGRect rect =CGRectMake(166, 211, 426, 320);//這裡可以設置想要截圖的區域 
  CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect); 
  UIImage *sendImage = [[UIImage alloc] initWithCGImage:imageRefRect]; 
  UIImageWriteToSavedPhotosAlbum(sendImage, nil, nil, nil);//保存圖片到照片庫 
  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];//保存照片到沙盒目錄 
  CGImageRelease(imageRefRect); 
  i++; 
} 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved