Git Product home page Git Product logo

scanner-overlay's Introduction

ScannerOverlay

ScannerOverlay extends AVCaptureVideoPreviewLayer with an overlay. You can define a masked area and setup the corners.

Installation

You can either install it via Swift Package Manager or copy the class from the Sources folder into your project.

Usage

At first setup your AVCaptureSession, then initiate the ScannerOverlay with it, and after that add it as a sublayer to your view.

  let scannerOverlayPreviewLayer              = ScannerOverlayPreviewLayer(session: captureSession)
  scannerOverlayPreviewLayer.frame            = self.view.bounds
  scannerOverlayPreviewLayer.maskSize         = CGSize(width: 200, height: 200)
  scannerOverlayPreviewLayer.videoGravity     = .resizeAspectFill
  self.view.layer.addSublayer(scannerOverlayPreviewLayer)

If you want to limit the video capturing to the masked area you have to set the rectOfInterest of your AVCaptureMetadataOutput.

  metadataOutput.rectOfInterest = scannerOverlayPreviewLayer.rectOfInterest

Keep in mind that the overlay won't show in the simulator - for testing run the code on your device.

For an example implementation refer to the demo project in the Sources folder.

Settings

Parameter Description
maskSize Specifies the size of the masked area
cornerLength Specifies the length of the corners
lineWidth Specifies the line width of the corners
lineColor Specifies the line color of the corners
lineCap Specifies the line cap of the corner endpoints
backgroundColor Specifies the backgroundColor of the outer masked area
cornerRadius Specifies the corner radius of the masked area

License

ScannerOverlay is available under the MIT license. See the LICENSE file for more info.

scanner-overlay's People

Contributors

gaebel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

scanner-overlay's Issues

Adding a CAShapeLayer goes out of bounds

let path = CGMutablePath()
            qrCodeView.clipsToBounds = true
            view.clipsToBounds = true
            path.addRect(videoPreviewLayer!.bounds)
            path.addRect(qrCodeFrameView.frame)

            let maskLayer = CAShapeLayer()
            maskLayer.path = path
            maskLayer.fillColor = UIColor.black.withAlphaComponent(0.6).cgColor
            maskLayer.fillRule = .evenOdd

            videoPreviewLayer?.addSublayer(maskLayer)

I have the above code but my path extends beyond the bounds of my qrCodeFrameView, what could be the problem.

IMG_3128

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.