Search in sources :

Example 1 with ImageProxy

use of androidx.camera.core.ImageProxy in project Signal-Android by signalapp.

the class CameraXFragment method onCaptureClicked.

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) {
                    Log.w(TAG, "Failed to encode captured image.", 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) {
            Log.w(TAG, "Failed to capture image", exception);
            flashHelper.endFlash();
            controller.onCameraError();
        }
    });
    flashHelper.startFlash();
}
Also used : RequiresApi(androidx.annotation.RequiresApi) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) WindowManager(android.view.WindowManager) ImageView(android.widget.ImageView) Animator(android.animation.Animator) R(org.thoughtcrime.securesms.R) ProcessCameraProvider(androidx.camera.lifecycle.ProcessCameraProvider) VideoUtil(org.thoughtcrime.securesms.video.VideoUtil) View(android.view.View) Animation(android.view.animation.Animation) ContextCompat(androidx.core.content.ContextCompat) Executors(com.bumptech.glide.util.Executors) ImageProxy(androidx.camera.core.ImageProxy) Surface(android.view.Surface) ImageCapture(androidx.camera.core.ImageCapture) ViewGroup(android.view.ViewGroup) MediaCountIndicatorButton(org.thoughtcrime.securesms.mediasend.v2.MediaCountIndicatorButton) Log(org.signal.core.util.logging.Log) Nullable(androidx.annotation.Nullable) AnimationCompleteListener(org.thoughtcrime.securesms.animation.AnimationCompleteListener) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Context(android.content.Context) GestureDetector(android.view.GestureDetector) PreviewView(androidx.camera.view.PreviewView) CameraXUtil(org.thoughtcrime.securesms.mediasend.camerax.CameraXUtil) CameraSelector(androidx.camera.core.CameraSelector) AnimationUtils(android.view.animation.AnimationUtils) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) TooltipPopup(org.thoughtcrime.securesms.components.TooltipPopup) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) Toast(android.widget.Toast) ImageCaptureException(androidx.camera.core.ImageCaptureException) MemoryFileDescriptor(org.thoughtcrime.securesms.util.MemoryFileDescriptor) Build(android.os.Build) CameraXFlashToggleView(org.thoughtcrime.securesms.mediasend.camerax.CameraXFlashToggleView) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) LayoutInflater(android.view.LayoutInflater) MediaAnimations(org.thoughtcrime.securesms.mediasend.v2.MediaAnimations) IOException(java.io.IOException) SignalCameraView(androidx.camera.view.SignalCameraView) RotateAnimation(android.view.animation.RotateAnimation) Optional(org.whispersystems.libsignal.util.guava.Optional) Glide(com.bumptech.glide.Glide) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) Configuration(android.content.res.Configuration) DecryptableUri(org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) FileDescriptor(java.io.FileDescriptor) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) ImageCaptureException(androidx.camera.core.ImageCaptureException) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) ImageCapture(androidx.camera.core.ImageCapture) IOException(java.io.IOException) ImageProxy(androidx.camera.core.ImageProxy)

Example 2 with ImageProxy

use of androidx.camera.core.ImageProxy in project Signal-Android by WhisperSystems.

the class CameraXFragment method onCaptureClicked.

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) {
                    Log.w(TAG, "Failed to encode captured image.", 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) {
            Log.w(TAG, "Failed to capture image", exception);
            flashHelper.endFlash();
            controller.onCameraError();
        }
    });
    flashHelper.startFlash();
}
Also used : RequiresApi(androidx.annotation.RequiresApi) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) WindowManager(android.view.WindowManager) ImageView(android.widget.ImageView) Animator(android.animation.Animator) R(org.thoughtcrime.securesms.R) ProcessCameraProvider(androidx.camera.lifecycle.ProcessCameraProvider) VideoUtil(org.thoughtcrime.securesms.video.VideoUtil) View(android.view.View) Animation(android.view.animation.Animation) ContextCompat(androidx.core.content.ContextCompat) Executors(com.bumptech.glide.util.Executors) ImageProxy(androidx.camera.core.ImageProxy) Surface(android.view.Surface) ImageCapture(androidx.camera.core.ImageCapture) ViewGroup(android.view.ViewGroup) MediaCountIndicatorButton(org.thoughtcrime.securesms.mediasend.v2.MediaCountIndicatorButton) Log(org.signal.core.util.logging.Log) Nullable(androidx.annotation.Nullable) AnimationCompleteListener(org.thoughtcrime.securesms.animation.AnimationCompleteListener) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Context(android.content.Context) GestureDetector(android.view.GestureDetector) PreviewView(androidx.camera.view.PreviewView) CameraXUtil(org.thoughtcrime.securesms.mediasend.camerax.CameraXUtil) CameraSelector(androidx.camera.core.CameraSelector) AnimationUtils(android.view.animation.AnimationUtils) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) TooltipPopup(org.thoughtcrime.securesms.components.TooltipPopup) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) Toast(android.widget.Toast) ImageCaptureException(androidx.camera.core.ImageCaptureException) MemoryFileDescriptor(org.thoughtcrime.securesms.util.MemoryFileDescriptor) Build(android.os.Build) CameraXFlashToggleView(org.thoughtcrime.securesms.mediasend.camerax.CameraXFlashToggleView) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) LayoutInflater(android.view.LayoutInflater) MediaAnimations(org.thoughtcrime.securesms.mediasend.v2.MediaAnimations) IOException(java.io.IOException) SignalCameraView(androidx.camera.view.SignalCameraView) RotateAnimation(android.view.animation.RotateAnimation) Optional(org.whispersystems.libsignal.util.guava.Optional) Glide(com.bumptech.glide.Glide) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) Configuration(android.content.res.Configuration) DecryptableUri(org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) FileDescriptor(java.io.FileDescriptor) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) ImageCaptureException(androidx.camera.core.ImageCaptureException) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) ImageCapture(androidx.camera.core.ImageCapture) IOException(java.io.IOException) ImageProxy(androidx.camera.core.ImageProxy)

Aggregations

Animator (android.animation.Animator)2 SuppressLint (android.annotation.SuppressLint)2 Context (android.content.Context)2 Configuration (android.content.res.Configuration)2 Build (android.os.Build)2 Bundle (android.os.Bundle)2 GestureDetector (android.view.GestureDetector)2 LayoutInflater (android.view.LayoutInflater)2 MotionEvent (android.view.MotionEvent)2 Surface (android.view.Surface)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 WindowManager (android.view.WindowManager)2 Animation (android.view.animation.Animation)2 AnimationUtils (android.view.animation.AnimationUtils)2 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)2 RotateAnimation (android.view.animation.RotateAnimation)2 ImageView (android.widget.ImageView)2 Toast (android.widget.Toast)2 NonNull (androidx.annotation.NonNull)2