androidx.camera.core.ImageCapture Java Examples
The following examples show how to use
androidx.camera.core.ImageCapture.
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: CustomCameraView.java From PictureSelector with Apache License 2.0 | 6 votes |
private void setFlashRes() { switch (type_flash) { case TYPE_FLASH_AUTO: mFlashLamp.setImageResource(R.drawable.picture_ic_flash_auto); mCameraView.setFlash(ImageCapture.FLASH_MODE_AUTO); break; case TYPE_FLASH_ON: mFlashLamp.setImageResource(R.drawable.picture_ic_flash_on); mCameraView.setFlash(ImageCapture.FLASH_MODE_ON); break; case TYPE_FLASH_OFF: mFlashLamp.setImageResource(R.drawable.picture_ic_flash_off); mCameraView.setFlash(ImageCapture.FLASH_MODE_OFF); break; } }
Example #2
Source File: CameraXSelfieFlashHelper.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private boolean shouldUseViewBasedFlash() { Integer cameraLensFacing = camera.getCameraLensFacing(); return camera.getFlash() == ImageCapture.FLASH_MODE_ON && !camera.hasFlash() && cameraLensFacing != null && cameraLensFacing == CameraSelector.LENS_FACING_BACK; }
Example #3
Source File: CustomCameraView.java From PictureSelector with Apache License 2.0 | 5 votes |
@Override public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) { if (mConfigReference.get() != null) { if (SdkVersionUtils.checkedAndroid_Q() && PictureMimeType.isContent(mConfigReference.get().cameraPath)) { PictureThreadUtils.executeByIo(new PictureThreadUtils.SimpleTask<Boolean>() { @Override public Boolean doInBackground() { return AndroidQTransformUtils.copyPathToDCIM(mContextReference.get(), mFileReference.get(), Uri.parse(mConfigReference.get().cameraPath)); } @Override public void onSuccess(Boolean result) { PictureThreadUtils.cancel(PictureThreadUtils.getIoPool()); } }); } } if (mImageCallbackListenerReference.get() != null && mFileReference.get() != null && mImagePreviewReference.get() != null) { mImageCallbackListenerReference.get().onLoadImage(mFileReference.get(), mImagePreviewReference.get()); } if (mImagePreviewReference.get() != null) { mImagePreviewReference.get().setVisibility(View.VISIBLE); } if (mCaptureLayoutReference.get() != null) { mCaptureLayoutReference.get().startTypeBtnAnimator(); } }
Example #4
Source File: CameraXModule.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public void setFlash(@ImageCapture.FlashMode int flash) { this.mFlash = flash; if (mImageCapture == null) { // Do nothing if there is no imageCapture return; } mImageCapture.setFlashMode(flash); }
Example #5
Source File: CameraXModule.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
CameraXModule(CameraXView view) { mCameraXView = view; Futures.addCallback(ProcessCameraProvider.getInstance(view.getContext()), new FutureCallback<ProcessCameraProvider>() { // TODO(b/124269166): Rethink how we can handle permissions here. @SuppressLint("MissingPermission") @Override public void onSuccess(@Nullable ProcessCameraProvider provider) { Preconditions.checkNotNull(provider); mCameraProvider = provider; if (mCurrentLifecycle != null) { bindToLifecycle(mCurrentLifecycle); } } @Override public void onFailure(Throwable t) { throw new RuntimeException("CameraX failed to initialize.", t); } }, CameraXExecutors.mainThreadExecutor()); mPreviewBuilder = new Preview.Builder().setTargetName("Preview"); mImageCaptureBuilder = new ImageCapture.Builder().setTargetName("ImageCapture"); // Begin Signal Custom Code Block mVideoCaptureConfigBuilder = new VideoCaptureConfig.Builder().setTargetName("VideoCapture") .setAudioBitRate(VideoUtil.AUDIO_BIT_RATE) .setVideoFrameRate(VideoUtil.VIDEO_FRAME_RATE) .setBitRate(VideoUtil.VIDEO_BIT_RATE); // End Signal Custom Code Block }
Example #6
Source File: CameraXFlashToggleView.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private static FlashMode fromImageCaptureFlashMode(@ImageCapture.FlashMode int flashMode) { for (FlashMode mode : values()) { if (mode.getFlashMode() == flashMode) { return mode; } } throw new AssertionError(); }
Example #7
Source File: CameraXFlashToggleView.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public void setFlash(@ImageCapture.FlashMode int mode) { FlashMode flashMode = FlashMode.fromImageCaptureFlashMode(mode); flashIndex = resolveFlashIndex(FLASH_MODES.indexOf(flashMode), supportsFlashModeAuto); refreshDrawableState(); notifyListener(); }
Example #8
Source File: CameraXFlashToggleView.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
@ImageCapture.FlashMode int getFlashMode() { return flashMode; }
Example #9
Source File: CameraXFlashToggleView.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
FlashMode(@ImageCapture.FlashMode int flashMode) { this.flashMode = flashMode; }
Example #10
Source File: CameraXModule.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
@ImageCapture.FlashMode public int getFlash() { return mFlash; }
Example #11
Source File: CameraXView.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private void init(Context context, @Nullable AttributeSet attrs) { addView(mPreviewView = new PreviewView(getContext()), 0 /* view position */); mCameraModule = new CameraXModule(this); if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CameraXView); setScaleType( ScaleType.fromId( a.getInteger(R.styleable.CameraXView_scaleType, getScaleType().getId()))); setPinchToZoomEnabled( a.getBoolean( R.styleable.CameraXView_pinchToZoomEnabled, isPinchToZoomEnabled())); setCaptureMode( CaptureMode.fromId( a.getInteger(R.styleable.CameraXView_captureMode, getCaptureMode().getId()))); int lensFacing = a.getInt(R.styleable.CameraXView_lensFacing, LENS_FACING_BACK); switch (lensFacing) { case LENS_FACING_NONE: setCameraLensFacing(null); break; case LENS_FACING_FRONT: setCameraLensFacing(CameraSelector.LENS_FACING_FRONT); break; case LENS_FACING_BACK: setCameraLensFacing(CameraSelector.LENS_FACING_BACK); break; default: // Unhandled event. } int flashMode = a.getInt(R.styleable.CameraXView_flash, 0); switch (flashMode) { case FLASH_MODE_AUTO: setFlash(ImageCapture.FLASH_MODE_AUTO); break; case FLASH_MODE_ON: setFlash(ImageCapture.FLASH_MODE_ON); break; case FLASH_MODE_OFF: setFlash(ImageCapture.FLASH_MODE_OFF); break; default: // Unhandled event. } a.recycle(); } if (getBackground() == null) { setBackgroundColor(0xFF111111); } mPinchToZoomGestureDetector = new PinchToZoomGestureDetector(context); }
Example #12
Source File: CameraXView.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
/** Gets the active flash strategy. */ @ImageCapture.FlashMode public int getFlash() { return mCameraModule.getFlash(); }
Example #13
Source File: CameraXView.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
/** Sets the active flash strategy. */ public void setFlash(@ImageCapture.FlashMode int flashMode) { mCameraModule.setFlash(flashMode); }
Example #14
Source File: CameraXUtil.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public static @NonNull @ImageCapture.CaptureMode int getOptimalCaptureMode() { return FastCameraModels.contains(Build.MODEL) ? ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY : ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY; }
Example #15
Source File: CameraXFragment.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private void onCaptureClicked() { Stopwatch stopwatch = new Stopwatch("Capture"); CameraXSelfieFlashHelper flashHelper = new CameraXSelfieFlashHelper( requireActivity().getWindow(), camera, selfieFlash ); camera.takePicture(Executors.mainThreadExecutor(), new ImageCapture.OnImageCapturedCallback() { @Override public void onCaptureSuccess(@NonNull ImageProxy image) { flashHelper.endFlash(); SimpleTask.run(CameraXFragment.this.getViewLifecycleOwner().getLifecycle(), () -> { stopwatch.split("captured"); try { return CameraXUtil.toJpeg(image, camera.getCameraLensFacing() == CameraSelector.LENS_FACING_FRONT); } catch (IOException e) { return null; } finally { image.close(); } }, result -> { stopwatch.split("transformed"); stopwatch.stop(TAG); if (result != null) { controller.onImageCaptured(result.getData(), result.getWidth(), result.getHeight()); } else { controller.onCameraError(); } }); } @Override public void onError(ImageCaptureException exception) { flashHelper.endFlash(); controller.onCameraError(); } }); flashHelper.startFlash(); }
Example #16
Source File: MainActivity.java From journaldev with MIT License | 4 votes |
private ImageCapture setImageCapture() { ImageCaptureConfig imageCaptureConfig = new ImageCaptureConfig.Builder().setCaptureMode(ImageCapture.CaptureMode.MIN_LATENCY) .setTargetRotation(getWindowManager().getDefaultDisplay().getRotation()).build(); final ImageCapture imgCapture = new ImageCapture(imageCaptureConfig); btnCapture.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { imgCapture.takePicture(new ImageCapture.OnImageCapturedListener() { @Override public void onCaptureSuccess(ImageProxy image, int rotationDegrees) { Bitmap bitmap = textureView.getBitmap(); showAcceptedRejectedButton(true); ivBitmap.setImageBitmap(bitmap); } @Override public void onError(ImageCapture.UseCaseError useCaseError, String message, @Nullable Throwable cause) { super.onError(useCaseError, message, cause); } }); /*File file = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "" + System.currentTimeMillis() + "_JDCameraX.jpg"); imgCapture.takePicture(file, new ImageCapture.OnImageSavedListener() { @Override public void onImageSaved(@NonNull File file) { Bitmap bitmap = textureView.getBitmap(); showAcceptedRejectedButton(true); ivBitmap.setImageBitmap(bitmap); } @Override public void onError(@NonNull ImageCapture.UseCaseError useCaseError, @NonNull String message, @Nullable Throwable cause) { } });*/ } }); return imgCapture; }
Example #17
Source File: CameraXFlashToggleView.java From mollyim-android with GNU General Public License v3.0 | votes |
void flashModeChanged(@ImageCapture.CaptureMode int flashMode);