diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index c018988a..4514624b 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -870,6 +870,11 @@ public class CameraView extends FrameLayout implements LifecycleObserver { mExperimental = experimental; } + /** + * Sets the flag if you want disable restart camera on change mode (Photo/Video), + * but only for {@link Engine#CAMERA1} + * @param changeModeWithoutRestart - true if you want disable restart + */ public void setChangeModeWithoutRestart(boolean changeModeWithoutRestart) { mChangeModeWithoutRestart = changeModeWithoutRestart; } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java index 7c6ad4e2..e61ec24b 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java @@ -150,18 +150,7 @@ public class Camera1Engine extends CameraBaseEngine implements protected void prepareNewMode() { mCaptureSize = computeCaptureSize(); Camera.Parameters params = mCamera.getParameters(); - if (getMode() == Mode.PICTURE) { - // setPictureSize is allowed during preview - params.setPictureSize(mCaptureSize.getWidth(), mCaptureSize.getHeight()); - } else { - // mCaptureSize in this case is a video size. The available video sizes are not - // necessarily a subset of the picture sizes, so we can't use the mCaptureSize value: - // it might crash. However, the setPictureSize() passed here is useless : we don't allow - // HQ pictures in video mode. - // While this might be lifted in the future, for now, just use a picture capture size. - Size pictureSize = computeCaptureSize(Mode.PICTURE); - params.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight()); - } + setPictureSize(params); applyDefaultFocus(params); params.setRecordingHint(getMode() == Mode.VIDEO); mCamera.setParameters(params); @@ -238,18 +227,7 @@ public class Camera1Engine extends CameraBaseEngine implements params.setPreviewFormat(ImageFormat.NV21); // setPreviewSize is not allowed during preview params.setPreviewSize(mPreviewStreamSize.getWidth(), mPreviewStreamSize.getHeight()); - if (getMode() == Mode.PICTURE) { - // setPictureSize is allowed during preview - params.setPictureSize(mCaptureSize.getWidth(), mCaptureSize.getHeight()); - } else { - // mCaptureSize in this case is a video size. The available video sizes are not - // necessarily a subset of the picture sizes, so we can't use the mCaptureSize value: - // it might crash. However, the setPictureSize() passed here is useless : we don't allow - // HQ pictures in video mode. - // While this might be lifted in the future, for now, just use a picture capture size. - Size pictureSize = computeCaptureSize(Mode.PICTURE); - params.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight()); - } + setPictureSize(params); mCamera.setParameters(params); mCamera.setPreviewCallbackWithBuffer(null); // Release anything left diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java index 398de415..1c1ac52d 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java @@ -2,6 +2,7 @@ package com.otaliastudios.cameraview.engine; import android.graphics.PointF; import android.graphics.RectF; +import android.hardware.Camera; import android.location.Location; import androidx.annotation.CallSuper; @@ -756,6 +757,21 @@ public abstract class CameraBaseEngine extends CameraEngine { : preview.getSurfaceSize(); } + void setPictureSize(Camera.Parameters params) { + if (getMode() == Mode.PICTURE) { + // setPictureSize is allowed during preview + params.setPictureSize(mCaptureSize.getWidth(), mCaptureSize.getHeight()); + } else { + // mCaptureSize in this case is a video size. The available video sizes are not + // necessarily a subset of the picture sizes, so we can't use the mCaptureSize value: + // it might crash. However, the setPictureSize() passed here is useless : we don't allow + // HQ pictures in video mode. + // While this might be lifted in the future, for now, just use a picture capture size. + Size pictureSize = computeCaptureSize(Mode.PICTURE); + params.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight()); + } + } + /** * Returns the snapshot size, but not cropped with the view dimensions, which * is what we will do before creating the snapshot. However, cropping is done at various