androidx.camera.core.Camera Java Examples
The following examples show how to use
androidx.camera.core.Camera.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PublishFragment.java From lbry-android with MIT License | 6 votes |
private void displayPreviewWithCameraX() { Context context = getContext(); if (context != null && MainActivity.hasPermission(Manifest.permission.CAMERA, context)) { cameraProviderFuture = ProcessCameraProvider.getInstance(context); cameraProviderFuture.addListener(new Runnable() { @Override public void run() { try { ProcessCameraProvider cameraProvider = cameraProviderFuture.get(); if (cameraProvider != null) { Preview preview = new Preview.Builder().build(); CameraSelector cameraSelector = new CameraSelector.Builder() .requireLensFacing(CameraSelector.LENS_FACING_BACK) .build(); Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, preview); preview.setSurfaceProvider(cameraPreview.createSurfaceProvider(camera.getCameraInfo())); cameraPreviewInitialized = true; } } catch (ExecutionException | IllegalArgumentException | InterruptedException ex) { // pass } } }, ContextCompat.getMainExecutor(context)); } }
Example #2
Source File: CameraXModule.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
@Nullable public Camera getCamera() { return mCamera; }
Example #3
Source File: CameraXView.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
/** * Focus the position of the touch event, or focus the center of the preview for * accessibility events */ @Override public boolean performClick() { super.performClick(); final float x = (mUpEvent != null) ? mUpEvent.getX() : getX() + getWidth() / 2f; final float y = (mUpEvent != null) ? mUpEvent.getY() : getY() + getHeight() / 2f; mUpEvent = null; CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing( mCameraModule.getLensFacing()).build(); DisplayOrientedMeteringPointFactory pointFactory = new DisplayOrientedMeteringPointFactory( getDisplay(), cameraSelector, mPreviewView.getWidth(), mPreviewView.getHeight()); float afPointWidth = 1.0f / 6.0f; // 1/6 total area float aePointWidth = afPointWidth * 1.5f; MeteringPoint afPoint = pointFactory.createPoint(x, y, afPointWidth); MeteringPoint aePoint = pointFactory.createPoint(x, y, aePointWidth); Camera camera = mCameraModule.getCamera(); if (camera != null) { ListenableFuture<FocusMeteringResult> future = camera.getCameraControl().startFocusAndMetering( new FocusMeteringAction.Builder(afPoint, FocusMeteringAction.FLAG_AF).addPoint(aePoint, FocusMeteringAction.FLAG_AE).build()); Futures.addCallback(future, new FutureCallback<FocusMeteringResult>() { @Override public void onSuccess(@Nullable FocusMeteringResult result) { } @Override public void onFailure(Throwable t) { // Throw the unexpected error. throw new RuntimeException(t); } }, CameraXExecutors.directExecutor()); } else { Log.d(TAG, "cannot access camera"); } return true; }