I am developing an application where I have to take picture without using Media intent i-e without previewing this camera.How can I do this can anyone help me in this regard.
waiting for your reply
Altaf
You cannot take a picture without a preview. Whether it is the preview offered by the Intent or it is a preview that you create yourself with a SurfaceView when you use the Camera object, there has to be a preview.
Just use takePicture() directly on the camera object:
http://developer.android.com/reference/android/hardware/Camera.html#takePicture
I believe some of the older devices wouldn't capture correctly unless preview was setup, but I don't think that's an issue any more. And if you are looking to target devices that require preview you can just resize the preview surface to a single pixel somewhere and put another control on top of it. Still eats resources, but shouldn't be visible.
Related
I am new with android studio and I have a question about camera.I have done the Take photo tutorial and now I have a button that opens my camera app. I want to take the color of a pixel from the camera app without saving the picture.
It is possible or I need to make camera API in order to take that color?
Any suggestion or tips about how I can make this project are welcomed.
Android camera intent either saves an image file, or it is cancelled. You need camera API approach to catch pixels without creating files. You can use a library like fotoapparat to wraps the tricky API for easy usage.
Is there any way to have a camera preview using the camera2 library while running the application? I only need one method which is able to show in the app the camera preview (not taking pictures or opening the camera APP).
Take a look at CameraView, an unofficial support library widget for drawing camera preview easily (It can also take snapshots, but you can ignore that part).
I tried few codes from here :
How to capture an image in background without using the camera application
and this
Android Camera API Tutorial.
This question may seem duplicated, but I really want to know that can this be done over API level 21?
Thanks in advance.
According to android.developer.com, no.
https://developer.android.com/reference/android/hardware/Camera.html
"Important: Call startPreview() to start updating the preview surface. Preview must be started before you can take a picture."
I am new to Android, i want to take pictures in background without surface view/preview. I have searched online but the methods don't seem working for me. I want to use the latest Camera2 API.
Regards!
Muhammad Awais
Just create an ImageReader, and a camera capture session with that ImageReader's Surface. No need to have a SurfaceView or TextureView as well.
You'll need to stream some number of captures before starting to save any, though, to ensure that the auto-exposure/focus/etc routines of the camera have time to converge.
when I make a call to mCamera.takePicture(null, null, null, null); (for simplicity I have omitted the callbacks) the preview freezes and shows a preview of the scene that was just captured. Why is that the case. Can I somehow control this behaviour? And, what does actually happen? Is there a new view that gets attached or does my camera preview simple stop?
What does actually happen? Is there a new view that gets attached or does my camera preview simply stop?
No new view gets attached by default. The preview just stops. The documentation for Camera states this clearly:
Preview will be stopped after the image is taken; callers must call startPreview() again if they want to re-start preview or take more pictures.
It also goes on to say:
After calling this method, you must not call startPreview() or take another picture until the JPEG callback has returned.
So, the best place to call startPreview() again would be the JPEG callback. Any time before that, the camera hardware is still processing the previous image, and wouldn't be able to give you a preview. That's the main reason that it "freezes"; the camera hardware is just busy.
It's also a visual cue to the user that:
a picture was taken
the picture looks like "this"
That's icing on the cake, but even if you didn't care about that, it would still do it.
Can I somehow control this behaviour?
Through the publicly expose API? Definitely not. You can restart the preview once the camera is done processing(as above), but you can't prevent it from freeze-framing when you call takePicture().
Whether it's possible by going further into the camera firmware, I can't really say. However, since there are roughly a bazillion different cameras used in Android devices, this would likely be an exercise in futility if you weren't working on one specific device.
Even with one specific device, I can't see how you'd overcome it altogether. At a bare minimum, the camera will be busy processing the image for some amount of time. Even high-end DSLR cameras that I've seen freeze the preview at least for the duration of the exposure.
After calling takePicture() you can hide the preview surface under another view (e.g. ImageView). If you use OpenGL to render the preview texture instead of SurfaceView, you have even more tricks in your sleeve.