How do I use the metadataOutputRectOfInterestForRect method and rectOfInterest property to scan a specific area? (QR Code)

前端 未结 8 1978
时光说笑
时光说笑 2020-12-04 18:00

I am building a QR code scanner with Swift and everything works in that regard. The issue I have is that I am trying to make only a small area of the entire visible A

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 18:36

    /// After

    captureSession.startRunning()
    

    /// Add this

    if let videoPreviewLayer = self.videoPreviewLayer {
    self.captureMetadataOutput.rectOfInterest =
    videoPreviewLayer.metadataOutputRectOfInterest(for:
    self.getRectOfInterest())
    
    
    fileprivate func getRectOfInterest() -> CGRect {
            let centerX = (self.frame.width / 2) - 100
            let centerY = (self.frame.height / 2) - 100
            let quadr: CGFloat = 200
    
            let myRect = CGRect(x: centerX, y: centerY, width: quadr, height: quadr)
    
            return myRect
        }
    

提交回复
热议问题