Capture picture without preview using camera2 API
You should capture photos in "onConfigured" function but not onImageAvailable.
public void onConfigured(CameraCaptureSession session) {
cameraCaptureSession = session;
createCaptureRequest();
}
In this function "onImageAvailable",you should save images,
Image image = mImageReader.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
try {
save(bytes, file);
} catch (IOException e) {
e.printStackTrace();
}
image.close();
"onImageAvailable" function will be invoked after session.capture() .
Capturing image without making preview choppy using Camera 2 API
If the camera device is a LEGACY-level device, this is unfortunately expected.
Even for a LIMITED device, the camera has to support the BURST_CAPTURE capability to guarantee full-resolution capture at a fast rate. All FULL-level or better devices do support BURST_CAPTURE.
However, even on lower-capability devices, you can typically capture uncompressed YUV frames at video recording resolutions smoothly. That means adding in an ImageReader with a YUV_420_888 format to your session configuration, and then processing the Images that come out of that. JPEGs on LEGACY devices are unfortunately always slow, and some LEGACY devices don't have enough CPU power to smoothly produce the YUV data either (because there have to be some conversions under the hood).
For more detail, you can inspect the outputs of StreamConfigurationMap and see what output YUV resolutions run at a minimum frame duration of 1/30s; those should guarantee smooth operation for LIMITED or better devices.
Related Topics
What Is the Real World Accuracy of Phone Accelerometers When Used for Positioning
Retrieve Contact Phone Number from Uri in Android
Limitation on Texture Size? Android Open Gl Es 2.0
Android Emulator Not Receiving Push Notifications
Android - Margins Specified in Custom Style Not Taking Effect
Read Contents of a Url in Android
Cordova - Error: Failed to Fetch Platform Android
How to Detect App Removed from the Recent List
Android Options Menu Icon Won't Display
Android 2.1 View's Getdrawingcache() Method Always Returns Null
Compatiblity of Material Design to Versions Below Android 5.0
Getting Height of Text View Before Rendering to Layout
Android - Wake Up and Unlock Device
How to Implement Google Maps Search by Address in Android
How to Use Sms Content Provider? Where Are the Docs
Android Layout Animations from Bottom to Top and Top to Bottom on Imageview Click
When Should One Use Rxjava Observable and When Simple Callback on Android