camera-samples | Multiple samples showing the best practices
kandi X-RAY | camera-samples Summary
kandi X-RAY | camera-samples Summary
This repository contains a set of individual Android Studio projects to help you get started with the CameraX and Camera2 APIs in Android.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of camera-samples
camera-samples Key Features
camera-samples Examples and Code Snippets
Community Discussions
Trending Discussions on camera-samples
QUESTION
I need to use the Android Camera. Therefore I am using following Template: https://github.com/android/camera-samples/tree/main/Camera2SlowMotion
I added a Butten to the fragment_camera.xml https://github.com/android/camera-samples/blob/main/Camera2SlowMotion/app/src/main/res/layout/fragment_camera.xml
...ANSWER
Answered 2022-Mar-25 at 05:33I had to download the sample because I couldn't see what the issue was from the snippets in your post.
The issue is that CameraFragment
has two layout files, one in the default folder layout
, and one in layout-land
for landscape orientation. So you need to add your change_focus_button
XML to both layout files to make it not nullable
when you access it via fragmentCameraBinding
in CameraFragment
.
QUESTION
I am using CameraX and want to take a photo. Of course, no one wants a blurred picture, so we should ensure focused before taking picture.
First attempt: Simply call takePicture
like what is done in the official sample.
Problem: I can change the scene and quickly press the take photo button. Then, the camera has not finished auto focus when the takePicture happens. Therefore, I get a blurred photo :/
Second attempt: Before actually taking photo, firstly trigger focusing and wait for it to finish.
Code like:
...ANSWER
Answered 2021-Sep-19 at 07:35I found the answer! Simply call setCaptureMode(ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY)
.
Reason: look at ImageCapture's constructor:
QUESTION
The official sample of Camera2Basic for capturing images from camera.
It only shows the captured image in an activity but does not save the image to external storage
How to save that image to external storage?
I searched a lot over the internet for this, but there are all of the deprecated as of Android 11 (API 30).
Thanks!
ANSWER
Answered 2021-Apr-10 at 07:00use camerax lib from google which is part android jetpack
QUESTION
I'm trying to implement the Camera2 API in my application. Having never done this before, I'm starting with the Camera2Basic example code provided by android.
However, within the createCaptureSession()
method there is a deprecated initialization method CameraDevice.createCaptureSession()
, so I changed it to the following:
ANSWER
Answered 2021-Apr-09 at 12:45The documentation might resolve your problem:
As per this link:
To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). To dispatch events through a shared thread pool, you can use AsyncTask#THREAD_POOL_EXECUTOR.
You might get rid of the variable cameraHandler
by using equivalent methods:
CameraCaptureSession#capture
-> CameraCaptureSession#captureSingleRequest
CameraCaptureSession#setRepeatingRequest
-> CameraCaptureSession#setSingleRepeatingRequest
and so on.
But be aware, that the method you mentioned (CameraDevice#createCaptureSession(java.util.List, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler)
) was introduced in API 24 and deprecated in API 30, but the CameraDevice#createCaptureSession(SessionConfiguration)
was introduced only in API 28. So very probably You would need to handle API differences.
QUESTION
I'm reading sample of code of using RenderScript (https://github.com/android/camera-samples/blob/be17bffb7b1dcc69467a52bcb94bec4306c3ca4b/HdrViewfinder/Application/src/main/rs/hdr_merge.rs#L27) and documentation (https://developer.android.com/guide/topics/renderscript/compute#writing-an-rs-kernel). There are 2 different ways of defining kernel:
...ANSWER
Answered 2021-Feb-26 at 12:14Ok, after detailed reading I can see that RS_KERNEL
is a macro to __attribute__((kernel))
QUESTION
I'm still practicing with Kotlin and Android Developing. As far as I understood, Camera class has been deprecated, and Android invites to use Camerax instead, because this high-level class is device-indipendent, and they've made simpler the process of implementing cameras on apps.
I've tried to read the documentation (https://developer.android.com/training/camerax) but it's written so bad I barely understood what they are trying to explain. So I went to read the entire sample code given in the documentation itself (https://github.com/android/camera-samples/tree/main/CameraXBasic). The CameraFragment code is about 500 lines long (ignoring imports and various comments).
Do I really need to write 500 lines of code to simply take a picture? How is this supposed to be considered "simpler than before"?
I mean, Android programming is at the point where I just need to write only 4 lines of code to ask the user to select an Image from his storage and retreive it and show it in an ImageView. Is there a TRUE simple way to take a picture, or do I really need to stop and lose a whole day of work to write all those lines of code?
EDIT: Take this page of the documentation: https://developer.android.com/training/camerax/architecture#kotlin It starts with this piece of code.
...ANSWER
Answered 2021-Feb-23 at 01:10Before you can interact with the device's cameras using CameraX, you need to initialize the library. The initialization process is asynchronous, and involves things like loading information about the device's cameras.
You interact with the device's cameras using a ProcessCameraProvider
. It's a Singleton, so the first time you get an instance of if, CameraX performs its initialization.
QUESTION
We have 2 distinct memory leaks(which look the same) in $ git clone https://source.codeaurora.org/quic/la/camera-samples -b iot-concam-apk.lnx.1.1
in version 2.0 and they go away on app close.
They occurs as soon as the app is launched. Switching tabs, again and again, does not increase the number of leaks which is a good thing I think.
I caught it using https://square.github.io/leakcanary/getting_started/ I noticed if we change all 'replace' to add in onCreate, the 2 leaks happen on Tab switch and not on the app launch.
...ANSWER
Answered 2021-Feb-13 at 08:57I have fixed the memory leak.
Not using androidx.fragment.app.FragmentContainerView
in my XML was the solution.
Instead, I have used a ConstraintLayout.
I think you should not use it if you do not control your fragment using app:navGraph="@navigation/nav_graph"
in XML and instead use replace(R.id.fragment_container, null, null)
in your activity
QUESTION
Disclaimer: I'm aware of the existence of this question, but it currently stands unresolved and I'm trying to provide extra information without polluting that one with useless answers that won't solve the problem anyway.
I have a custom device with a front camera that is mirrored by default, so I want to display the preview normally and I need to horizontally flip the content of PreviewView, but I'm stuck. Other people in the past have suggested using PreviewView#setScaleX(-1)
but it either doesn't work at all or it needs to be called at a very specific point in the code, which I haven't found yet.
The code below is a simplified version of CameraFragment.kt
in the official CameraXBasic example; I've added comments where I've already tired calling viewFinder.scaleX = -1f
with no success. Honestly I don't really think that the place makes a difference because if I call it with any value other than 1 it works fine with both scaleX
and scaleY
, but it always ignores the negative sign so it never flips.
ANSWER
Answered 2021-Jan-05 at 21:08Depending on the implementation type (COMPATIBLE
vs PERFORMANCE
) and the device, PreviewView
can either use a TextureView
or a SurfaceView
, in your case I'm assuming PreviewView
is using a SurfaceView
, you can confirm this by getting access to PreviewView
's first child view (View.getChildAt(0)
).
TextureView
is just like any other View
, which is why when PreviewView
uses it, setting its scaleX to -1 should mirror the displayed preview. You can call PreviewView.setScaleX(-1F)
once the layout is created (e.g. In onViewCreated()
).
With SurfaceView
, it's a bit tricky, as the Surface
and the View
are independent in some aspects: The Surface
is placed behind the window that holds the View
, and the View hierarchy handles correctly composing the entire layout by punching a hole in the window in order to display SurfaceView
's Surface
. This might explain why mirroring the content SurfaceView
displays isn't possible, though I'm not sure why zooming in (scaleX set to values > 1) and out (scaleX set to values between 0 and 1) work nonetheless.
QUESTION
There are a couple of samples to get the relative rotation from the camera sensor to the current device orientation, e.g. for using it for correcting camera preview or for MediaRecorder.setOrientationHint(int)
But the newest method from the latest official github camera samples works different than older methods (for deprecated camera2 API and method from archived camera2 sample)
Here's my sample code that uses all methods and logs all results, we can see that function computeRelativeRotationCamera2New
returns different result for Surface.ROTATION_90
and Surface.ROTATION_270
display rotation
So what is the correct method to do it?
...ANSWER
Answered 2020-Jul-31 at 07:19Tested recorded videos with different methods and found out that the newest method from the latest sample is incorrect for landscape video recording, it plays videos upside down
I decided to update old method that uses deprecated camera api to use camera2 api (works for 21+ API) and use it in my project
QUESTION
As I understand from many implementations such as :
https://github.com/android/camera-samples/tree/master/CameraXBasic
https://proandroiddev.com/android-camerax-preview-analyze-capture-1b3f403a9395
After every use case in CameraX implementation cameraProvide.bindToLifecycle() method needs to be called.
For example, if I need to switch ON the FLASH_MODE of the camera from the default OFF mode, then again bindToLifecycle() method needs to be called.
The disadvantage with this approach is that for a second or two the preview is removed and re-attached which doesn't feel like a smooth transition for an app.
Is there any better practice available or it is the limitation?
I Have attached a sample code below:
...ANSWER
Answered 2020-Jun-05 at 17:59To enable or disable the flash during an image capture after you've created an ImageCapture
instance and bound it to a lifecycle, you can use ImageCapture.setFlashMode(boolean)
.
Regarding your question about the difference between setting the flash mode before vs after binding the ImageCapture
use case, AFAIK there isn't much of a difference really. When you take a picture by calling ImageCapture.takePicture()
, a capture request is built using different configuration parameters, one of them is the flash mode. So as long as the flash mode is set before this call (ImageCapture.takePicture()
), the output of the capture request should be the same.
CameraX currently uses Camera2 under the hood, to better understand how the flash mode is set when taking a picture, you can take a look at CaptureRequest.FLASH_MODE.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install camera-samples
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page