IOS 开发之ios视频截屏的实现代码
程序员文章站
2023-12-21 14:32:52
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++; }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!