Top Related Projects
[DEPRECATED] Easily integrate Camera features into your Android app
📸 A well documented, high-level Android interface that makes capturing pictures and videos easy, addressing all of the common issues and needs. Real-time filters, gestures, watermarks, frame processing, RAW, output of any size.
Library for Android Camera 1 and 2 APIs. Massively increase stability and reliability of photo and video capture on all Android devices.
PhotoView For Fresco
Image Cropping Library for Android, optimized for Camera / Gallery.
Quick Overview
Fotoapparat is a modern, lightweight Android camera library that simplifies the process of integrating camera functionality into Android applications. It provides a high-level API for camera operations, including capturing photos, applying filters, and handling various camera parameters.
Pros
- Easy to use and integrate into existing Android projects
- Supports both front and back cameras with automatic switching
- Provides a wide range of camera controls and settings
- Offers built-in image processing capabilities and filters
Cons
- Limited documentation and examples for advanced use cases
- May not support all features on older Android devices
- Requires additional setup for certain functionalities (e.g., QR code scanning)
- Less active development compared to some other camera libraries
Code Examples
- Basic camera setup and photo capture:
val fotoapparat = Fotoapparat(
context = this,
view = cameraView
)
fotoapparat.start()
captureButton.setOnClickListener {
fotoapparat.takePicture().toBitmap().whenAvailable { bitmapPhoto ->
// Process the captured photo
}
}
- Switching between front and back cameras:
val frontCamera = front()
val backCamera = back()
fotoapparat.switchTo(frontCamera)
// ... later
fotoapparat.switchTo(backCamera)
- Applying a filter to the camera preview:
fotoapparat.updateConfiguration(
CameraConfiguration(
previewFilter = PreviewFilter.BlurFilter(10f)
)
)
Getting Started
To use Fotoapparat in your Android project, follow these steps:
- Add the dependency to your
build.gradle
file:
dependencies {
implementation 'io.fotoapparat:fotoapparat:2.7.0'
}
- Add camera permissions to your
AndroidManifest.xml
:
<uses-permission android:name="android.permission.CAMERA" />
- Initialize Fotoapparat in your activity or fragment:
private lateinit var fotoapparat: Fotoapparat
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
fotoapparat = Fotoapparat(
context = this,
view = findViewById(R.id.camera_view)
)
}
override fun onStart() {
super.onStart()
fotoapparat.start()
}
override fun onStop() {
super.onStop()
fotoapparat.stop()
}
Now you can use Fotoapparat to capture photos and control the camera in your Android app.
Competitor Comparisons
[DEPRECATED] Easily integrate Camera features into your Android app
Pros of cameraview
- Backed by Google, potentially offering better long-term support and integration with Android ecosystem
- Simpler API with fewer abstractions, making it easier for beginners to use
- Provides a custom view (CameraView) for easy integration into layouts
Cons of cameraview
- Less feature-rich compared to Fotoapparat, with fewer advanced camera controls
- Limited customization options for camera parameters and settings
- Slower development cycle and less frequent updates
Code Comparison
Fotoapparat:
val fotoapparat = Fotoapparat(
context = this,
view = cameraView,
scaleType = ScaleType.CenterCrop,
lensPosition = back(),
logger = loggers(
logcat()
),
cameraErrorCallback = { error -> Log.e("Fotoapparat", "Camera error: ", error) }
)
cameraview:
val cameraView = findViewById<CameraView>(R.id.camera)
cameraView.setLifecycleOwner(this)
cameraView.addCameraListener(object : CameraListener() {
override fun onPictureTaken(result: PictureResult) {
// Handle the picture
}
})
Both libraries offer easy-to-use APIs for camera functionality in Android apps. Fotoapparat provides more advanced features and customization options, while cameraview offers a simpler approach with potentially better long-term support from Google. The choice between the two depends on the specific requirements of your project and your familiarity with camera APIs.
📸 A well documented, high-level Android interface that makes capturing pictures and videos easy, addressing all of the common issues and needs. Real-time filters, gestures, watermarks, frame processing, RAW, output of any size.
Pros of CameraView
- More comprehensive feature set, including advanced camera controls and filters
- Better documentation and examples for easier integration
- Active development with frequent updates and bug fixes
Cons of CameraView
- Larger library size, potentially increasing app size
- Steeper learning curve due to more complex API
- May be overkill for simple camera implementations
Code Comparison
CameraView:
cameraView.setLifecycleOwner(this)
cameraView.addCameraListener(object : CameraListener() {
override fun onPictureTaken(result: PictureResult) {
// Handle the captured image
}
})
cameraView.takePicture()
Fotoapparat:
val fotoapparat = Fotoapparat(
context = this,
view = cameraView
)
fotoapparat.takePicture().whenAvailable { photo ->
// Handle the captured image
}
Both libraries offer straightforward ways to capture images, but CameraView provides a more object-oriented approach with listeners, while Fotoapparat uses a functional style with callbacks. CameraView's API is more extensive, reflecting its broader feature set, while Fotoapparat's API is simpler and more focused on basic camera functionality.
Library for Android Camera 1 and 2 APIs. Massively increase stability and reliability of photo and video capture on all Android devices.
Pros of camerakit-android
- More comprehensive feature set, including video capture and advanced camera controls
- Better performance optimization, especially for older devices
- Larger community and more frequent updates
Cons of camerakit-android
- Steeper learning curve due to more complex API
- Larger library size, which may impact app size
- Some features require paid plans
Code Comparison
Fotoapparat:
val fotoapparat = Fotoapparat(
context = this,
view = cameraView,
scaleType = ScaleType.CenterCrop
)
fotoapparat.start()
fotoapparat.takePicture()
camerakit-android:
cameraKitView.start()
cameraKitView.captureImage { cameraKitImage ->
val bitmap = cameraKitImage.bitmap
// Process the captured image
}
Both libraries offer simple APIs for basic camera operations, but camerakit-android provides more advanced features and customization options. Fotoapparat focuses on simplicity and ease of use, making it a good choice for projects with basic camera requirements. camerakit-android is better suited for applications needing more advanced camera functionality and performance optimizations.
PhotoView For Fresco
Pros of PhotoDraweeView
- Specialized for image viewing and zooming, offering a more focused solution
- Built on top of Fresco, leveraging its powerful image loading and caching capabilities
- Supports custom touch gestures for enhanced user interaction
Cons of PhotoDraweeView
- Limited to image viewing functionality, unlike Fotoapparat's comprehensive camera features
- Requires Fresco as a dependency, which may increase app size
- Less active development and community support compared to Fotoapparat
Code Comparison
PhotoDraweeView:
val photoDraweeView = findViewById<PhotoDraweeView>(R.id.photo_drawee_view)
photoDraweeView.setPhotoUri(Uri.parse("https://example.com/image.jpg"))
photoDraweeView.setOnPhotoTapListener { view, x, y -> /* Handle tap */ }
Fotoapparat:
val fotoapparat = Fotoapparat(
context = this,
view = cameraView,
scaleType = ScaleType.CenterCrop
)
fotoapparat.start()
fotoapparat.takePicture().whenAvailable { photo -> /* Handle captured photo */ }
While PhotoDraweeView focuses on displaying and interacting with images, Fotoapparat provides a complete camera solution with capture capabilities. The code snippets highlight their different purposes and usage patterns.
Image Cropping Library for Android, optimized for Camera / Gallery.
Pros of Android-Image-Cropper
- Specialized for image cropping with advanced features like aspect ratio, rotation, and shape customization
- Lightweight and focused on a single task, making it easier to integrate for specific cropping needs
- Provides a built-in UI for image cropping, reducing development time
Cons of Android-Image-Cropper
- Limited to image cropping functionality, unlike Fotoapparat's comprehensive camera features
- May require additional libraries for camera capture and image processing tasks
- Less actively maintained, with fewer recent updates compared to Fotoapparat
Code Comparison
Android-Image-Cropper:
CropImage.activity(imageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(1, 1)
.start(this)
Fotoapparat:
val fotoapparat = Fotoapparat(
context = this,
view = cameraView,
scaleType = ScaleType.CenterCrop
)
fotoapparat.start()
Both libraries offer easy-to-use APIs, but Fotoapparat focuses on camera functionality, while Android-Image-Cropper specializes in image cropping. Fotoapparat provides a more comprehensive solution for camera-related tasks, while Android-Image-Cropper excels in its specific domain of image cropping.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Fotoapparat
Camera API in Android is hard. Having 2 different API for new and old Camera does not make things any easier. But fret not, that is your lucky day! After several years of working with Camera, we came up with Fotoapparat.
What it provides:
- Camera API which does not allow you to shoot yourself in the foot.
- Simple yet powerful parameters customization.
- Standalone custom
CameraView
which can be integrated into anyActivity
. - Fixes and workarounds for device-specific problems.
- Both Kotlin and Java friendly configurations.
- Last, but not least, non 0% test coverage.
Taking picture becomes as simple as:
val fotoapparat = Fotoapparat(
context = this,
view = cameraView
)
fotoapparat.start()
fotoapparat
.takePicture()
.saveToFile(someFile)
How it works
Step One
Add CameraView
to your layout
<io.fotoapparat.view.CameraView
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Step Two
Configure Fotoapparat
instance.
Fotoapparat(
context = this,
view = cameraView, // view which will draw the camera preview
scaleType = ScaleType.CenterCrop, // (optional) we want the preview to fill the view
lensPosition = back(), // (optional) we want back camera
cameraConfiguration = configuration, // (optional) define an advanced configuration
logger = loggers( // (optional) we want to log camera events in 2 places at once
logcat(), // ... in logcat
fileLogger(this) // ... and to file
),
cameraErrorCallback = { error -> } // (optional) log fatal errors
)
Check the wiki for the configuration
options e.g. change iso
Are you using Java only? See our wiki for the java-friendly configuration.
Step Three
Call start()
and stop()
. No rocket science here.
override fun onStart() {
super.onStart()
fotoapparat.start()
}
override fun onStop() {
super.onStop()
fotoapparat.stop()
}
Take a picture
Finally, we are ready to take a picture. You have various options.
val photoResult = fotoapparat.takePicture()
// Asynchronously saves photo to file
photoResult.saveToFile(someFile)
// Asynchronously converts photo to bitmap and returns the result on the main thread
photoResult
.toBitmap()
.whenAvailable { bitmapPhoto ->
val imageView = (ImageView) findViewById(R.id.result)
imageView.setImageBitmap(bitmapPhoto.bitmap)
imageView.setRotation(-bitmapPhoto.rotationDegrees)
}
// Of course, you can also get a photo in a blocking way. Do not do it on the main thread though.
val result = photoResult.toBitmap().await()
// Convert asynchronous events to RxJava 1.x/2.x types.
// See /fotoapparat-adapters/ module
photoResult
.toBitmap()
.toSingle()
.subscribe { bitmapPhoto ->
}
Update parameters
It is also possible to update some parameters after Fotoapparat
was already started.
fotoapparat.updateConfiguration(
UpdateConfiguration(
flashMode = if (isChecked) torch() else off()
// ...
// all the parameters available in CameraConfiguration
)
)
Or alternatively, you may provide updates on an existing full configuration.
val configuration = CameraConfiguration(
// A full configuration
// ...
)
fotoapparat.updateConfiguration(
configuration.copy(
flashMode = if (isChecked) torch() else off()
// all the parameters available in CameraConfiguration
)
)
Switch cameras
In order to switch between cameras, Fotoapparat.switchTo()
can be used with the new desired lensPosition
and its cameraConfiguration
.
fotoapparat.switchTo(
lensPosition = front(),
cameraConfiguration = newConfigurationForFrontCamera
)
Set up
Add dependency to your build.gradle
implementation 'io.fotoapparat:fotoapparat:2.7.0'
Camera permission will be automatically added to your AndroidManifest.xml
. Do not forget to request this permission on Marshmallow and higher.
Face detection
Optionally, you can check out our other library which adds face detection capabilities - FaceDetector.
Credits
We want to say thanks to Mark Murphy for the awesome job he did with CWAC-Camera. We were using his library for a couple of years and now we feel that Fotoapparat is a next step in the right direction.
We also want to say many thanks to Leander Lenzing for the amazing icon. Don't forget to follow his work in dribbble.
License
Copyright 2017 Fotoapparat
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Top Related Projects
[DEPRECATED] Easily integrate Camera features into your Android app
📸 A well documented, high-level Android interface that makes capturing pictures and videos easy, addressing all of the common issues and needs. Real-time filters, gestures, watermarks, frame processing, RAW, output of any size.
Library for Android Camera 1 and 2 APIs. Massively increase stability and reliability of photo and video capture on all Android devices.
PhotoView For Fresco
Image Cropping Library for Android, optimized for Camera / Gallery.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot