这可能是在黑暗中拍摄,但如果您阅读 README.md https://github.com/lwansbrough/react-native-camera的第一段,它会说:
这些文档适用于进行中的 v1 版本。如果你想使用最新最好的并且可以处理严重的不稳定性,你可以使用 npm install --save lwansbrough/react-native-camera 安装。
该库的 NPM 版本为 0.3.8:https ://www.npmjs.com/package/react-native-camera 。
编辑:
所以我去在 0.3.8 安装库并node_modules
查看 Java 代码(假设你在 Android 手机上测试它)并搜索本机capture
函数,实际上没有任何东西可以处理该metadata
选项,这很可悲. 尝试搜索metadata
,您将找不到任何东西:
@ReactMethod
public void capture(final ReadableMap options, final Promise promise) {
int orientation = options.hasKey("orientation") ? options.getInt("orientation") : RCTCamera.getInstance().getOrientation();
if (orientation == RCT_CAMERA_ORIENTATION_AUTO) {
_sensorOrientationChecker.onResume();
_sensorOrientationChecker.registerOrientationListener(new RCTSensorOrientationListener() {
@Override
public void orientationEvent() {
int deviceOrientation = _sensorOrientationChecker.getOrientation();
_sensorOrientationChecker.unregisterOrientationListener();
_sensorOrientationChecker.onPause();
captureWithOrientation(options, promise, deviceOrientation);
}
});
} else {
captureWithOrientation(options, promise, orientation);
}
}
private void captureWithOrientation(final ReadableMap options, final Promise promise, int deviceOrientation) {
Camera camera = RCTCamera.getInstance().acquireCameraInstance(options.getInt("type"));
if (null == camera) {
promise.reject("No camera found.");
return;
}
if (options.getInt("mode") == RCT_CAMERA_CAPTURE_MODE_VIDEO) {
record(options, promise);
return;
}
RCTCamera.getInstance().setCaptureQuality(options.getInt("type"), options.getString("quality"));
if (options.hasKey("playSoundOnCapture") && options.getBoolean("playSoundOnCapture")) {
MediaActionSound sound = new MediaActionSound();
sound.play(MediaActionSound.SHUTTER_CLICK);
}
if (options.hasKey("quality")) {
RCTCamera.getInstance().setCaptureQuality(options.getInt("type"), options.getString("quality"));
}
final Boolean shouldMirror = options.hasKey("mirrorImage") && options.getBoolean("mirrorImage");
RCTCamera.getInstance().adjustCameraRotationToDeviceOrientation(options.getInt("type"), deviceOrientation);
camera.takePicture(null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
if (shouldMirror) {
data = mirrorImage(data);
if (data == null) {
promise.reject("Error mirroring image");
}
}
camera.stopPreview();
camera.startPreview();
WritableMap response = new WritableNativeMap();
switch (options.getInt("target")) {
case RCT_CAMERA_CAPTURE_TARGET_MEMORY:
String encoded = Base64.encodeToString(data, Base64.DEFAULT);
response.putString("data", encoded);
promise.resolve(response);
break;
case RCT_CAMERA_CAPTURE_TARGET_CAMERA_ROLL: {
File cameraRollFile = getOutputCameraRollFile(MEDIA_TYPE_IMAGE);
if (cameraRollFile == null) {
promise.reject("Error creating media file.");
return;
}
Throwable error = writeDataToFile(data, cameraRollFile);
if (error != null) {
promise.reject(error);
return;
}
addToMediaStore(cameraRollFile.getAbsolutePath());
response.putString("path", Uri.fromFile(cameraRollFile).toString());
promise.resolve(response);
break;
}
case RCT_CAMERA_CAPTURE_TARGET_DISK: {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile == null) {
promise.reject("Error creating media file.");
return;
}
Throwable error = writeDataToFile(data, pictureFile);
if (error != null) {
promise.reject(error);
return;
}
addToMediaStore(pictureFile.getAbsolutePath());
response.putString("path", Uri.fromFile(pictureFile).toString());
promise.resolve(response);
break;
}
case RCT_CAMERA_CAPTURE_TARGET_TEMP: {
File tempFile = getTempMediaFile(MEDIA_TYPE_IMAGE);
if (tempFile == null) {
promise.reject("Error creating media file.");
return;
}
Throwable error = writeDataToFile(data, tempFile);
if (error != null) {
promise.reject(error);
}
response.putString("path", Uri.fromFile(tempFile).toString());
promise.resolve(response);
break;
}
}
}
});
}
但是,我查看了 iOS 端,发现它们确实在metadata
那里处理了该对象。
编辑:
此外,该master
分支仍然不处理该metadata
选项。见这里。似乎您必须指定一个特定的target
并且取决于它是什么,它会返回一个特定的数据类型,但不幸的是与位置无关。