mirror of
https://github.com/status-im/react-native-camera.git
synced 2026-08-31 13:41:08 +00:00
Added Camera.constants.CaptureQuality.preview for android to allow the outputted image to be exactly the same as the previewed image (#449)
This commit is contained in:
committed by
Nicolas Charpentier
parent
e4536fd896
commit
154cb7aa58
@@ -11,6 +11,7 @@ import android.util.Log;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.lang.Math;
|
||||
|
||||
public class RCTCamera {
|
||||
private static RCTCamera ourInstance;
|
||||
@@ -112,6 +113,24 @@ public class RCTCamera {
|
||||
return smallestSize;
|
||||
}
|
||||
|
||||
private Camera.Size getClosestSize(List<Camera.Size> supportedSizes, int matchWidth, int matchHeight) {
|
||||
Camera.Size closestSize = null;
|
||||
for (Camera.Size size : supportedSizes) {
|
||||
if (closestSize == null) {
|
||||
closestSize = size;
|
||||
continue;
|
||||
}
|
||||
|
||||
int currentDelta = Math.abs(closestSize.width - matchWidth) * Math.abs(closestSize.height - matchHeight);
|
||||
int newDelta = Math.abs(size.width - matchWidth) * Math.abs(size.height - matchHeight);
|
||||
|
||||
if (newDelta < currentDelta) {
|
||||
closestSize = size;
|
||||
}
|
||||
}
|
||||
return closestSize;
|
||||
}
|
||||
|
||||
protected List<Camera.Size> getSupportedVideoSizes(Camera camera) {
|
||||
Camera.Parameters params = camera.getParameters();
|
||||
// defer to preview instead of params.getSupportedVideoSizes() http://bit.ly/1rxOsq0
|
||||
@@ -203,7 +222,11 @@ public class RCTCamera {
|
||||
pictureSize = supportedSizes.get(supportedSizes.size() / 2);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_HIGH:
|
||||
pictureSize = getBestSize(supportedSizes, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
pictureSize = getBestSize(parameters.getSupportedPictureSizes(), Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_PREVIEW:
|
||||
Camera.Size optimalPreviewSize = getBestSize(parameters.getSupportedPreviewSizes(), Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
pictureSize = getClosestSize(parameters.getSupportedPictureSizes(), optimalPreviewSize.width, optimalPreviewSize.height);
|
||||
break;
|
||||
case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_480P:
|
||||
pictureSize = getBestSize(supportedSizes, RESOLUTION_480P.width, RESOLUTION_480P.height);
|
||||
|
||||
@@ -73,6 +73,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
|
||||
public static final int RCT_CAMERA_TORCH_MODE_OFF = 0;
|
||||
public static final int RCT_CAMERA_TORCH_MODE_ON = 1;
|
||||
public static final int RCT_CAMERA_TORCH_MODE_AUTO = 2;
|
||||
public static final String RCT_CAMERA_CAPTURE_QUALITY_PREVIEW = "preview";
|
||||
public static final String RCT_CAMERA_CAPTURE_QUALITY_HIGH = "high";
|
||||
public static final String RCT_CAMERA_CAPTURE_QUALITY_MEDIUM = "medium";
|
||||
public static final String RCT_CAMERA_CAPTURE_QUALITY_LOW = "low";
|
||||
@@ -196,6 +197,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
|
||||
put("medium", RCT_CAMERA_CAPTURE_QUALITY_MEDIUM);
|
||||
put("high", RCT_CAMERA_CAPTURE_QUALITY_HIGH);
|
||||
put("photo", RCT_CAMERA_CAPTURE_QUALITY_HIGH);
|
||||
put("preview", RCT_CAMERA_CAPTURE_QUALITY_PREVIEW);
|
||||
put("480p", RCT_CAMERA_CAPTURE_QUALITY_480P);
|
||||
put("720p", RCT_CAMERA_CAPTURE_QUALITY_720P);
|
||||
put("1080p", RCT_CAMERA_CAPTURE_QUALITY_1080P);
|
||||
|
||||
Reference in New Issue
Block a user