diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
index 37b3a521..7af2089f 100644
--- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
+++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
@@ -201,6 +201,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
boolean pictureSnapshotMetering = a.getBoolean(
R.styleable.CameraView_cameraPictureSnapshotMetering,
DEFAULT_PICTURE_SNAPSHOT_METERING);
+ int snapshotMaxWidth = a.getInteger(R.styleable.CameraView_cameraSnapshotMaxWidth, 0);
+ int snapshotMaxHeight = a.getInteger(R.styleable.CameraView_cameraSnapshotMaxHeight, 0);
// Size selectors and gestures
SizeSelectorParser sizeSelectors = new SizeSelectorParser(a);
@@ -257,6 +259,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
setVideoBitRate(videoBitRate);
setAutoFocusResetDelay(autoFocusResetDelay);
setPreviewFrameRate(videoFrameRate);
+ setSnapshotMaxWidth(snapshotMaxWidth);
+ setSnapshotMaxHeight(snapshotMaxHeight);
// Apply gestures
mapGesture(Gesture.TAP, gestures.getTapAction());
@@ -966,6 +970,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
setVideoBitRate(oldEngine.getVideoBitRate());
setAutoFocusResetDelay(oldEngine.getAutoFocusResetDelay());
setPreviewFrameRate(oldEngine.getPreviewFrameRate());
+ setSnapshotMaxWidth(oldEngine.getSnapshotMaxWidth());
+ setSnapshotMaxHeight(oldEngine.getSnapshotMaxHeight());
}
/**
@@ -1553,47 +1559,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
mListeners.clear();
}
- /**
- * Adds a {@link FrameProcessor} instance to be notified of
- * new frames in the preview stream.
- *
- * @param processor a frame processor.
- */
- public void addFrameProcessor(@Nullable FrameProcessor processor) {
- if (processor != null) {
- mFrameProcessors.add(processor);
- if (mFrameProcessors.size() == 1) {
- mCameraEngine.setHasFrameProcessors(true);
- }
- }
- }
-
- /**
- * Remove a {@link FrameProcessor} that was previously registered.
- *
- * @param processor a frame processor
- */
- public void removeFrameProcessor(@Nullable FrameProcessor processor) {
- if (processor != null) {
- mFrameProcessors.remove(processor);
- if (mFrameProcessors.size() == 0) {
- mCameraEngine.setHasFrameProcessors(false);
- }
- }
- }
-
- /**
- * Clears the list of {@link FrameProcessor} that have been registered
- * to preview frames.
- */
- public void clearFrameProcessors() {
- boolean had = mFrameProcessors.size() > 0;
- mFrameProcessors.clear();
- if (had) {
- mCameraEngine.setHasFrameProcessors(false);
- }
- }
-
/**
* Asks the camera to capture an image of the current scene.
* This will trigger {@link CameraListener#onPictureTaken(PictureResult)} if a listener
@@ -2275,6 +2240,73 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
//endregion
+ //region Frame Processing
+
+ /**
+ * Adds a {@link FrameProcessor} instance to be notified of
+ * new frames in the preview stream.
+ *
+ * @param processor a frame processor.
+ */
+ public void addFrameProcessor(@Nullable FrameProcessor processor) {
+ if (processor != null) {
+ mFrameProcessors.add(processor);
+ if (mFrameProcessors.size() == 1) {
+ mCameraEngine.setHasFrameProcessors(true);
+ }
+ }
+ }
+
+ /**
+ * Remove a {@link FrameProcessor} that was previously registered.
+ *
+ * @param processor a frame processor
+ */
+ public void removeFrameProcessor(@Nullable FrameProcessor processor) {
+ if (processor != null) {
+ mFrameProcessors.remove(processor);
+ if (mFrameProcessors.size() == 0) {
+ mCameraEngine.setHasFrameProcessors(false);
+ }
+ }
+ }
+
+ /**
+ * Clears the list of {@link FrameProcessor} that have been registered
+ * to preview frames.
+ */
+ public void clearFrameProcessors() {
+ boolean had = mFrameProcessors.size() > 0;
+ mFrameProcessors.clear();
+ if (had) {
+ mCameraEngine.setHasFrameProcessors(false);
+ }
+ }
+
+ /**
+ * Sets the max width for frame processing {@link Frame}s.
+ * This option is only supported by {@link Camera2Engine} and will have no effect
+ * on other engines.
+ *
+ * @param maxWidth max width for frames
+ */
+ public void setFrameProcessingMaxWidth(int maxWidth) {
+ mCameraEngine.setFrameProcessingMaxWidth(maxWidth);
+ }
+
+ /**
+ * Sets the max height for frame processing {@link Frame}s.
+ * This option is only supported by {@link Camera2Engine} and will have no effect
+ * on other engines.
+ *
+ * @param maxHeight max height for frames
+ */
+ public void setFrameProcessingMaxHeight(int maxHeight) {
+ mCameraEngine.setFrameProcessingMaxHeight(maxHeight);
+ }
+
+ //endregion
+
//region Overlays
@Override
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 3c0eaf9d..0ccbfa7b 100644
--- a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java
+++ b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java
@@ -78,8 +78,8 @@ public abstract class CameraBaseEngine extends CameraEngine {
private int mAudioBitRate;
private boolean mHasFrameProcessors;
private long mAutoFocusResetDelayMillis;
- private int mSnapshotMaxWidth = Integer.MAX_VALUE; // in REF_VIEW like SizeSelectors
- private int mSnapshotMaxHeight = Integer.MAX_VALUE; // in REF_VIEW like SizeSelectors
+ private int mSnapshotMaxWidth; // in REF_VIEW like SizeSelectors
+ private int mSnapshotMaxHeight; // in REF_VIEW like SizeSelectors
private Overlay mOverlay;
// Ops used for testing.
@@ -721,6 +721,8 @@ public abstract class CameraBaseEngine extends CameraEngine {
boolean flip = getAngles().flip(reference, Reference.VIEW);
int maxWidth = flip ? mSnapshotMaxHeight : mSnapshotMaxWidth;
int maxHeight = flip ? mSnapshotMaxWidth : mSnapshotMaxHeight;
+ if (maxWidth <= 0) maxWidth = Integer.MAX_VALUE;
+ if (maxHeight <= 0) maxHeight = Integer.MAX_VALUE;
float baseRatio = AspectRatio.of(baseSize).toFloat();
float maxValuesRatio = AspectRatio.of(maxWidth, maxHeight).toFloat();
if (maxValuesRatio >= baseRatio) {
diff --git a/cameraview/src/main/res/values/attrs.xml b/cameraview/src/main/res/values/attrs.xml
index 371db28e..20361365 100644
--- a/cameraview/src/main/res/values/attrs.xml
+++ b/cameraview/src/main/res/values/attrs.xml
@@ -25,8 +25,8 @@
-
+
+