ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - CameraKit/camerakit-ios: Library for iOS Camera API. Massively increase performance and ease of use within your next iOS Project.
Library for iOS Camera API. Massively increase performance and ease of use within your next iOS Project. - CameraKit/camerakit-ios
Visit Site

GitHub - CameraKit/camerakit-ios: Library for iOS Camera API. Massively increase performance and ease of use within your next iOS Project.

GitHub - CameraKit/camerakit-ios: Library for iOS Camera API. Massively increase performance and ease of use within your next iOS Project.

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service that scales, and endless camera possibilities.

With CameraKit you are able to effortlessly do the following:

  • ✅ Ability to extend and create custom sessions.
  • ✅ Image and video capture seamlessly working with the same preview session.
  • ✅ Automatic system permission handling.
  • ✅ Automatic preview scaling.
  • ✅ Automatic preview/image/video output orientation handling.
  • 📷 Ability to set a custom resolution for capturing photos.
  • 📹 Ability to set resolution/frame rate for capturing videos.
  • 👱‍ Built-in face detection.
  • 📐 Built-in overlay grid.
  • 👆 Built-in tap to focus.
  • 🔍 Built-in pinch to zoom.
  • 📸 Built-in flash toggle for both photos and videos.
  • 🤳 Built-in camera position toggle.
  • 🖥 Objective-C compatible.

Sponsored By

Installation

Demo

If you want to test out the demo app first you can clone this repo to your local disk:

git clone https://github.com/CameraKit/camerakit-ios.git

and then navigate to camerakit-ios and open the CameraKit.xcworkspace file with Xcode. Near the run button select the CameraKitDemo scheme, resolve the signing conflicts using your Apple account and then run it on a real device. You cannot do much on a simulator, since we need an actual camera hardware.

Cocoapods

If you don't have Cocoapods already installed you can install it by running the code below in a terminal:

sudo gem install cocoapods

If you don't have any Podfile run:

pod init

Then open the Podfile file in your project and add this line to your app target:

pod CameraKit-iOS

and it will automatically create a Podfile and integrate the pods into the project by creating a separate .xcworkspace file. You will open this file in Xcode from now on.

Carthage

If you don't have Carthage installed run:

brew install carthage

Then create a Cartfile and add the following line:

github "CameraKit/camerakit-ios"

Code

Before adding our camera related code, make sure you include the permissions needed for your code to work in the app project Info.plist file:

<!-- Required for photos and videos -->
<key>NSCameraUsageDescription</key>
<string></string>

<!-- Optional for photos -->
<key>NSMicrophoneUsageDescription</key>
<string></string>

<!-- Optional for the demo app to copy the photos/videos to your photo library -->
<key>NSPhotoLibraryAddUsageDescription</key>
<string></string>

Below is a quick start code sample with session + live camera preview:

import CameraKit

...

override func viewDidLoad() {
    super.viewDidLoad()

    // Init a photo capture session
    let session = CKFPhotoSession()
    
    // Use CKFVideoSession for video capture
    // let session = CKFVideoSession()
    
    let previewView = CKFPreviewView(frame: self.view.bounds)
    previewView.session = session
}

For capturing a image using the CKFPhotoSession class use this code below:

session.capture({ (image, settings) in
    // TODO: Add your code here
}) { (error) in
    // TODO: Handle error
}

If you want to record a video using the CKFVideoSession class use this code below to start the recording:

// You can also specify a custom url for where to save the video file
session.record(url: URL(string: ""), { (url) in
    // TODO: Add your code here
}) { (error) in
    // TODO: Handle error
}

and end the recording:

// You can also specify a custom url for where to save the video file
session.stopRecording()

You can get the current record status via the isRecording property to determine if a recording is in progress or not.

Session properties and methods

CKFPhotoSession CKFVideoSession
zoom: Double zoom: Double
resolution: CGSize isRecording: Bool
cameraPosition: CameraPosition cameraPosition: CameraPosition
cameraDetection: CameraDetection flashMode: FlashMode
flashMode: FlashMode start()
start() stop()
stop() togglePosition()
focus(at point: CGPoint) setWidth(_ width: Int, height: Int, frameRate: Int)
togglePosition() record(url: URL? = nil, _ callback: @escaping (URL) -> Void, error: @escaping (Error) -> Void)
capture(_ callback: @escaping (UIImage, AVCaptureResolvedPhotoSettings) -> Void, _ error: @escaping (Error) -> Void) stopRecording()

Import into Objective-C projects

Go to Project Settings, Build Settings, Always Embed Swift Standard Libraries and set the value to Yes.

Then import the CameraKit framework using:

@import CameraKit;

Creating custom sessions

CameraKit can be splitted into 2 main pieces: preview and sessions. The sessions are made by extending the base CKFSession class. If you want a custom session you can extend the CKFSession class and use its static helpers to initialize yours. Or you can also extend the built-in sessions and add custom logic.

class MyCustomSession: CKFSession {

    public override init() {
        super.init()
        
        do {
            let deviceInput = try CKFSession.captureDeviceInput(type: .backCamera)
            self.session.addInput(deviceInput)
        } catch let error {
            print(error.localizedDescription)
        }
    }

    // TODO: Add your code here
}

License

CameraKit is released under the MIT License.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory