ios开发之视频截屏的实例代码-kb88凯时官网登录

时间:2023-04-15
阅读:
免费资源网 - https://freexyz.cn/

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  ; 
}
免费资源网 - https://freexyz.cn/
返回顶部
顶部
网站地图