这是我的类configureLocalPrevIEw方法,它将视频流与UIVIEws连接起来:
@IBOutlet var remoteVIEw: RTCEAGLVIDeoVIEw!@IBOutlet var localVIEw: UIVIEw!var captureSession: AVCaptureSession?var vIDeoSource: RTCAVFoundationVIDeoSource?var vIDeoTrack: RTCVIDeoTrack?func configureLocalPrevIEw() { self.vIDeoTrack = self.signaling.localMediaStream.self.vIDeoTracks.first as! RTCVIDeoTrack? self.vIDeoSource = (self.vIDeoTrack?.source as? RTCAVFoundationVIDeoSource) self.captureSession = self.vIDeoSource?.self.captureSession self.prevIEwLayer = AVCaptureVIDeoPrevIEwLayer.init(session: self.captureSession) self.prevIEwLayer.frame = self.localVIEw.bounds self.localVIEw.layer.addSublayer(self.prevIEwLayer) self.localVIEw.isUserInteractionEnabled = true //self.localVIEw.layer.position = CGPointMake(100,100);}
在我想要访问快照的地方,我打电话给:
self.localVIEw.pb_takeSnapshot()
pb_takeSnapshot来自UIVIEw扩展,我在另一篇文章中找到了它.它的定义如下:
extension UIVIEw { func pb_takeSnapshot() -> UIImage { UIGraphicsBeginImageContextWithOptions(bounds.size,false,UIScreen.main.scale) drawHIErarchy(in: self.bounds,afterScreenUpdates: true) let image = UIGraphicsGetimageFromCurrentimageContext()! UIGraphicsEndImageContext() return image }}
当我看一下Xcode调试器中的图像时,它看起来完全是绿色的,而我在iphone屏幕上(在该视图内)可以看到的人不在那里:
这个人不可见的原因是什么?难道不知道是不可能制作一个流的快照?谢谢你看看!
解决方法 您应该使用RTCEAGLVIDeoVIEw而不是UIVIEw创建localVIEw.我使用相同的localVIEw,并使用您的帖子中提到的相同代码片段拍摄快照.下面是示例代码,它将启动您的相机并显示本地预览:
class VIEwController: UIVIEwController,RTCEAGLVIDeoVIEwDelegate {var captureSession: AVCaptureSession?var prevIEwLayer :AVCaptureVIDeoPrevIEwLayer?var peerConnectionFactory: RTCPeerConnectionFactory!var vIDeoSource:RTCAVFoundationVIDeoSource!var localTrack :RTCVIDeoTrack!@IBOutlet var myVIEw: UIVIEw!overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() /*myVIEw = UIVIEw(frame: CGRect(x: 0,y: 0,wIDth: UIScreen.main.bounds.size.wIDth,height: UIScreen.main.bounds.size.height))*/ startCamera() // Do any additional setup after loading the vIEw,typically from a nib.}fileprivate func startCamera() { peerConnectionFactory = RTCPeerConnectionFactory() RTCInitializeSSL(); RTCSetupInternalTracer(); RTCSetMinDeBUGLogLevel(RTCLoggingSeverity.info) vIDeoSource = peerConnectionFactory.avFoundationVIDeoSource(with: nil); localTrack = peerConnectionFactory.vIDeoTrack(with: vIDeoSource,trackID: "ARdamSv0") let localScaleX = CGfloat(1.0) let localVIEw : RTCEAGLVIDeoVIEw = RTCEAGLVIDeoVIEw(frame: self.vIEw.bounds) self.vIEw.insertSubvIEw(localVIEw,at: 1) localVIEw.frame = self.vIEw.bounds; localVIEw.transform = CGAffinetransform(scaleX: localScaleX,y: 1) localTrack.add(localVIEw)}overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning() // dispose of any resources that can be recreated.}overrIDe func vIEwDIDAppear(_ animated: Bool) { //prevIEwLayer?.frame.size = myVIEw.frame.size}func vIDeoVIEw(_ vIDeoVIEw: RTCEAGLVIDeoVIEw,dIDChangeVIDeoSize size: CGSize) { print("InsIDe dIDChangeVIDeoSize")}}总结
以上是内存溢出为你收集整理的ios – 拍摄AVCaptureVideoPreviewLayer视图的快照全部内容,希望文章能够帮你解决ios – 拍摄AVCaptureVideoPreviewLayer视图的快照所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)