IOS 開發(fā)之ios視頻截屏的實(shí)現(xiàn)代碼
創(chuàng)新互聯(lián)建站主營遼陽網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶APP軟件開發(fā),遼陽h5小程序開發(fā)搭建,遼陽網(wǎng)站營銷推廣歡迎遼陽等地區(qū)企業(yè)咨詢
現(xiàn)在好多視頻截屏軟件,這里提供一個(gè)IOS 視頻截屏的方法,大家可以參考下,
實(shí)現(xiàn)代碼:
//截屏 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);//這里可以設(shè)置想要截圖的區(qū)域 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++; }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
網(wǎng)站題目:IOS開發(fā)之ios視頻截屏的實(shí)現(xiàn)代碼
路徑分享:http://aaarwkj.com/article4/peihie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、響應(yīng)式網(wǎng)站、企業(yè)網(wǎng)站制作、虛擬主機(jī)、品牌網(wǎng)站建設(shè)、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)