Coder Social home page Coder Social logo

mfcameramanager's Introduction

CameraManager Features :

● manage camera session

● get image from camera

● crop image in a frame

● scan barcode and get the image asynchronously

Requirements :

iOS 8.0+

Xcode 8.1+

Swift 3.0+ (Support Swift 4)


Demo :

www gifcreator me_3krqfy


Installation :

CocoaPods :

pod 'MFCameraManager'

or download CustomCameraManagerClass directory and add it manually to your project

Setup :

Now in your view add a UIView to storyboard view controller or programmetically initiate an UIView which will be your camera preview. then follow steps to display the camera :

If you just need the camera session and capturing image you have to use CameraManager.swift class, as it has StillImageOutput.

but if you need the camera session to scan barcode beside capturing image you have to use ScanBarcodeCameraManager.swift class, as it has StillImageOutput.

initial step

Create a variable of which class you prefer (ScanBarcodeCameraManager.swift or CameraManager.swift) :

var cameraManager = CameraManager()

or

var cameraManager = ScanBarcodeCameraManager()

from now on below 4 steps are similar in each class you instantiated :

1 - on your viewDidLoad setup the camera with your UIView created to show the camera preview inside it, and your camera position which its default is back :

cameraManager.captureSetup(in: self.cameraView, with: .back)

2 - in viewWillApear delegate call this method :

cameraManager.startRunning()

3 - in viewDidDisapear delegate call below method :

cameraManager.stopRunning()

4 - to support landscape transitions add below code to viewWillTransition Delegate :

cameraManager.transitionCamera()

Features in CameraManager class

  • to capture an image showing on camera :
self.cameraManager.getcroppedImage { (UIImage, error) in

          //your code here to handle with error or if error == nil , get the UIImage 
}
  • to get the image inside a frame or CGRect , give the frame as a params to getcroppedImage function like below :
self.cameraManager.getcroppedImage(with: self.rectLayer.frame) {  (UIImage, error) in
         
       //your code here to handle with error or if error == nil , get the UIImage 
           
 }

Features in ScanBarcodeCameraManager class

  • to get the scanned barcode and capture an image :

should conform to protocol ScanBarcodeCameraManagerDelegate and :

self.cameraManager.delegate = self

then implement the function to get the barcode objects and also the captured image :

func scanBarcodeCameraManagerDidRecognizeBarcode(barcode: Array<AVMetadataMachineReadableCodeObject>, image: UIImage?) {
        self.scanBarcodeCameraManager.stopRunning()
        print(barcode)
        // to whatever you like to the barcode objects and the image
        scanBarcodeCameraManager.startRunning()

    }

Extra features in all classess

  • to enable torch mode use below code with level of torch mode default is 1 :

cameraManager.enableTorchMode(level: 1)

Communication :

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

mfcameramanager's People

Contributors

maryamfekri avatar satish avatar

Watchers

 avatar

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.