Swifttty and easy camera framework for iOS.

Related tags

Image SwiftttCamera
Overview

SwiftttCamera

Swifttty and easy camera framework for iOS.

GitHub Action Build Status Swift 5.4 Latest release

Issues Follow on Twitter

View Demo · Report Bug · Request Feature

SwiftttCamera is a wrapper around AVFoundation that allows you to build your own powerful custom camera app without all the headaches of using AVFoundation directly.

Why use this?

Major headaches that SwiftttCamera automatically handles for you:

AVFoundation Headaches
  • Configuring and managing an AVCaptureSession.
  • Displaying the AVCaptureVideoPreviewLayer in a sane way relative to your camera's view.
  • Configuring the state of the AVCaptureDevice and safely changing its properties as needed, such as setting the flash mode and switching between the front and back cameras.
  • Adjusting the camera's focus and exposure in response to tap gestures.
  • Zooming the camera in response to pinch gestures.
  • Capturing a full-resolution photo from the AVCapturePhotoOutput.
Device Orientation Headaches
  • Changing the AVCaptureConnection's orientation appropriately when the device is rotated.
  • Detecting the actual orientation of the device when a photo is taken even if orientation lock is on by using the accelerometer, so that landscape photos are always rotated correctly.
  • (Optional) Returning a preview version of the image rotated to match the orientation of what was displayed by the camera preview, even if the user has orientation lock on.
  • (Optional) Asynchronously returning an orientation-normalized version of the captured image rotated so that the image orientation is always UIImage.Orientation.up, useful for reliably displaying images correctly on web services that might not respect EXIF image orientation tags.
Image Processing Headaches
  • (Optional) Cropping the captured image to the visible bounds of your camera's view.
  • (Optional) Returning a scaled-down version of the captured image.
  • Processing high-resolution images quickly and efficiently without overloading the device's memory or creating app-terminating memory leaks.

SwiftttCamera does many operations faster than UIImagePickerController's camera, such as switching between the front and back camera, and provides you the captured photos in the format you need, returning a cropped full-resolution image as quickly as UIImagePickerController returns the raw captured image on most devices. It allows all of the flexibility of AVFoundation without the need to reinvent the wheel, so you can focus on making a beautiful custom UI and doing awesome things with photos.

While both UIImagePickerController's camera and AVFoundation give you raw images that may not even be cropped the same as the live camera preview your users see, SwiftttCamera gives you a full-resolution image cropped to the same aspect ratio as your live preview's viewport as well as a preview image scaled to the pixel dimensions of that viewport, whether you want a square camera, a camera sized to the full screen, or something else.

SwiftttCamera is also smart at handling image orientation, a notoriously tricky part of images from both AVFoundation and UIImagePickerController. The orientation of the camera is magically detected correctly even if the user is taking landscape photos with orientation lock turned on, because SwiftttCamera checks the accelerometer to determine the real device orientation.

Installation

SwiftttCamera is available through Swift Package Manager:

dependencies: [
    .package(name: "SwiftttCamera", url: "https://github.com/rogerluan/SwiftttCamera", .upToNextMajor(from: "1.0.0")),
]

Demo

To run the demo project, clone or download the repo, and open SwiftttCameraDemo/SwiftttCameraDemo.xcodeproj

SwiftttCamera Benchmark UIImagePickerController Benchmark
SwiftttCamera Benchmark Average Run Time UIImagePickerController Benchmark Average Run Time

Usage

Add an instance of SwiftttCamera as a child of your view controller. Adjust the size and layout of SwiftttCamera's view however you'd like, and SwiftttCamera will automatically adjust the camera's preview window and crop captured images to match what is visible within its bounds.

import SwiftttCamera
import UIKit

class DemoViewController : UIViewController {
    private lazy var camera: SwiftttCamera = {
        let result = SwiftttCamera()
        result.delegate = self
        result.view.translatesAutoresizingMaskIntoConstraints = false
        return result
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        swiftttAddChild(camera)
        camera.view.frame = view.frame // Alternatively, you can set it up using autolayout
    }
}

extension DemoViewController : CameraDelegate {
    func cameraController(_ cameraController: CameraProtocol, didFinishCapturingImage capturedImage: CapturedImage) {
        // Handle the captured image
    }
}

Switch between the front and back cameras:

let newCameraDevice: CameraDevice = camera.cameraDevice.toggling()
guard SwiftttCamera.isCameraDeviceAvailable(newCameraDevice) else { return }
camera.cameraDevice = newCameraDevice

Set the camera's flash mode:

camera.cameraFlashMode = shouldEnable ? .on : .off

Set the camera's torch mode:

let shouldEnable = enabled && camera.isTorchAvailableForCurrentDevice
camera.cameraTorchMode = shouldEnable ? .on : .off

Take a picture:

camera.takePicture()

Use SwiftttCamera's delegate methods to retrieve the captured image object after taking a photo:

func cameraController(_ cameraController: CameraProtocol, didFinishCapturingImage capturedImage: CapturedImage) {
    // Optional protocol function
}

func cameraController(_ cameraController: CameraProtocol, didFinishScalingCapturedImage capturedImage: CapturedImage) {
    // Optional protocol function
}

func cameraController(_ cameraController: CameraProtocol, didFinishNormalizingCapturedImage capturedImage: CapturedImage) {
    // Optional protocol function
}

References

This project is strongly based off of FastttCamera, but since that project hasn't been maintained since 2016, this project aims to give life back to that awesome framework, with the same perks, but using more modern APIs, and limiting supported SDKs to iOS 13+ only. Huge thanks Laura Skelton, the creator of FastttCamera for creating such awesome project. Without her work, this project definitely wouldn't be possible. 💪

Contributions

If you spot something wrong, missing, or if you'd like to propose improvements to this project, please open an Issue or a Pull Request with your ideas and I promise to get back to you within 24 hours! 😇

License

This project is open source and covered by a standard 2-clause BSD license. That means you can use (publicly, commercially and privately), modify and distribute this project's content, as long as you mention Roger Oba as the original author of this code and reproduce the LICENSE text inside your app, repository, project or research paper.

Contact

Twitter: @rogerluan_

You might also like...
SwiftUI iOS app which applies CoreML Video Matting (background removal) model to the front camera stream
SwiftUI iOS app which applies CoreML Video Matting (background removal) model to the front camera stream

CoreML Camera Video Matting This is a simple iOS app which applies Video Matting (background removal) model to the front camera stream. Video Matting

Extract opening hours tags from a camera image

OpeningHoursPhoto Extract opening hours tags from a camera image This project is no longer active. The latest development is taking part as part of Go

📸 A wrapper for AVCaptureSession - The way easier to use the Camera.

Capturer A wrapper for AVCaptureSession - The way easier to use the Camera. Setting up let captureBody = CaptureBody( configuration: .init { $0.

AnylineFaceAuthentication pairs identity document scanning with a real-time liveness check utilizing the iPhone's camera, best suited for authenticating users over the internet.

AnylineFaceAuthentication AnylineFaceAuthentication pairs identity document scanning with a real-time liveness check utilizing the iPhone's camera, be

The camera shoot a photo when animals apear in the frame
The camera shoot a photo when animals apear in the frame

AutoCatDogCam The camera shoot a photo when animals apear in the frame. How to u

Metazoom - A virtual camera plugin to pixellatedly share your screen

MetaZoom A virtual camera plugin to pixellatedly share your screen. See LICENSE.

ImagePicker - selecting images from the photo albums, with allowed permissions /on real device accesing the camera
ImagePicker - selecting images from the photo albums, with allowed permissions /on real device accesing the camera

ImagePicker - selecting images from the photo albums, with allowed permissions /on real device accesing the camera, permission also needed/after picking an image it has the possibility to rename it

Reconstruct a 3D face with RGB-D images captured by iPhone X's TrueDepth camera.
Reconstruct a 3D face with RGB-D images captured by iPhone X's TrueDepth camera.

!TrueDepth camera can only be accessed on iPhone X or later. TODO Get the RGB-D files (This repository) Generate 3D face mesh with landmark detector a

Get  a photo which has effects like the system camera’s Portrait mode (on compatible devices).
Get a photo which has effects like the system camera’s Portrait mode (on compatible devices).

Blurring background like Portrait mode in the iPhone camera If we want to have the blurring effect like the Portrait mode in the iOS Camera app. What

Comments
  • SwiftUI Support?

    SwiftUI Support?

    Thanks for this great update to FastttCamera.

    One feature request: It would be great if SwiftttCamera also has first class SwiftUI support. That means that a SwiftUI View is provided so that it can be used directly in a SwiftUI app.

    opened by antranapp 6
Releases(0.9.0)
  • 0.9.0(Aug 28, 2021)

Owner
Roger Oba
Lead Mobile Engineer @zillyinc 🏡 @apple Developer Academy scholarship student  Core contributor @fastlane 🚀 7+ years of mobile app development 👨‍💻
Roger Oba
CameraEngine: The most advanced Camera framework in Swift

CameraEngine THIS REPOSITORY REFACTORED FROM ( https://github.com/remirobert/Cam

Mertcan Bulut 0 Jan 3, 2022
Kanvas is an open-source iOS library for adding effects, drawings, text, stickers, and making GIFs from existing media or the camera.

Kanvas Kanvas is an open-source iOS library for adding effects, drawings, text, stickers, and making GIFs from existing media or the camera.

Tumblr 267 Nov 24, 2022
Custom iOS camera and photo picker with editing capabilities

Overview Paparazzo is a component for picking and editing photos. Key Features ?? Taking photos using camera ?? Picking photos from user's photo libra

avito.tech 757 Jan 4, 2023
FlexibleImage is implemented with the hope that anyone could easily develop an app that provides features such as Camera Filter and Theme.

FlexibleImage is implemented with the hope that anyone could easily develop an app that provides features such as Camera Filter and Theme. When you wr

Jungwon An 815 Dec 30, 2022
Instant camera hybrid with multiple effects and filters written in Swift.

Kontax Cam Download on the app store! No longer on the app store Kontax Cam is an instant camera built 100% using Swift for iOS. You can take your pho

Kevin Laminto 108 Dec 27, 2022
A free, multiplatform SDK for real-time facial motion capture using blendshapes, and rigid head pose in 3D space from any RGB camera, photo, or video.

mocap4face by Facemoji mocap4face by Facemoji is a free, multiplatform SDK for real-time facial motion capture based on Facial Action Coding System or

Facemoji 592 Jan 1, 2023
CameraButton - A simple camera button that can be used for photo and video capturing

CameraButton A simple camera button that can be used for photo and video capturi

Erik Drobne 9 Dec 22, 2022
Simple camera application for iOS that uploads pictures to WebDAV server or Dropbox quickly. Available on the AppStore.

Upupu Simple camera application for iOS that uploads pictures to WebDAV server or Dropbox quickly. Also available on the AppStore. Features Easy and f

Xcoo 65 Nov 15, 2022
ImagePicker : an all-in-one camera solution for your iOS app

Description ImagePicker is an all-in-one camera solution for your iOS app. It lets your users select images from the library and take pictures at the

Özgür Odabaşı 1 Dec 1, 2021
FlaneurImagePicker is an iOS image picker that allows users to pick images from different sources (ex: user's library, user's camera, Instagram...). It's highly customizable.

FlaneurImagePicker is a highly customizable iOS image picker that allows users to pick images from different sources (ex: device's library, device's c

FlaneurApp 17 Feb 2, 2020