mirror of
https://github.com/status-im/react-native-camera.git
synced 2026-09-02 06:31:09 +00:00
add fixOrientation option (#682)
* optional fix orientation * comments * docs
This commit is contained in:
@@ -66,18 +66,22 @@ public class MutableImage {
|
||||
return;
|
||||
} else if (exifIFD0Directory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
|
||||
int exifOrientation = exifIFD0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
|
||||
rotate(exifOrientation);
|
||||
if(exifOrientation != 1) {
|
||||
rotate(exifOrientation);
|
||||
exifIFD0Directory.setInt(ExifIFD0Directory.TAG_ORIENTATION, 1);
|
||||
}
|
||||
}
|
||||
} catch (ImageProcessingException | IOException | MetadataException e) {
|
||||
throw new ImageMutationFailedException("failed to fix orientation", e);
|
||||
}
|
||||
}
|
||||
|
||||
//see http://www.impulseadventure.com/photo/exif-orientation.html
|
||||
private void rotate(int exifOrientation) throws ImageMutationFailedException {
|
||||
final Matrix bitmapMatrix = new Matrix();
|
||||
switch (exifOrientation) {
|
||||
case 1:
|
||||
break;
|
||||
return;//no rotation required
|
||||
case 2:
|
||||
bitmapMatrix.postScale(-1, 1);
|
||||
break;
|
||||
|
||||
@@ -524,8 +524,6 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
|
||||
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.setPreviewCallback(null);
|
||||
|
||||
@@ -538,7 +536,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
|
||||
AsyncTask.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
processImage(new MutableImage(data), shouldMirror, options, promise);
|
||||
processImage(new MutableImage(data), options, promise);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -560,13 +558,17 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
|
||||
* synchronized in order to prevent the user crashing the app by taking many photos and them all being processed
|
||||
* concurrently which would blow the memory (esp on smaller devices), and slow things down.
|
||||
*/
|
||||
private synchronized void processImage(MutableImage mutableImage, Boolean shouldMirror, ReadableMap options, Promise promise) {
|
||||
try {
|
||||
mutableImage.fixOrientation();
|
||||
} catch (MutableImage.ImageMutationFailedException e) {
|
||||
promise.reject("Error mirroring image", e);
|
||||
private synchronized void processImage(MutableImage mutableImage, ReadableMap options, Promise promise) {
|
||||
boolean shouldFixOrientation = options.hasKey("fixOrientation") && options.getBoolean("fixOrientation");
|
||||
if(shouldFixOrientation) {
|
||||
try {
|
||||
mutableImage.fixOrientation();
|
||||
} catch (MutableImage.ImageMutationFailedException e) {
|
||||
promise.reject("Error fixing orientation image", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean shouldMirror = options.hasKey("mirrorImage") && options.getBoolean("mirrorImage");
|
||||
if (shouldMirror) {
|
||||
try {
|
||||
mutableImage.mirrorImage();
|
||||
|
||||
Reference in New Issue
Block a user