capacitor-camera-module 0.0.35 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -71,7 +71,10 @@ import android.graphics.Rect;
|
|
|
71
71
|
import java.util.concurrent.Executors;
|
|
72
72
|
|
|
73
73
|
import java.util.concurrent.ExecutorService;
|
|
74
|
+
import java.io.File;
|
|
74
75
|
|
|
76
|
+
import androidx.exifinterface.media.ExifInterface;
|
|
77
|
+
import java.io.FileInputStream;
|
|
75
78
|
|
|
76
79
|
@CapacitorPlugin(
|
|
77
80
|
name = "CameraModule",
|
|
@@ -599,6 +602,7 @@ public class CameraModulePlugin extends Plugin {
|
|
|
599
602
|
) {
|
|
600
603
|
try {
|
|
601
604
|
Bitmap bitmap = BitmapFactory.decodeFile(photoFile.getAbsolutePath());
|
|
605
|
+
bitmap = rotateBitmapIfRequired(bitmap, photoFile);
|
|
602
606
|
Bitmap resized = resizeBitmap(bitmap, 1024);
|
|
603
607
|
|
|
604
608
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
@@ -842,6 +846,46 @@ public class CameraModulePlugin extends Plugin {
|
|
|
842
846
|
);
|
|
843
847
|
}
|
|
844
848
|
|
|
849
|
+
private Bitmap rotateBitmapIfRequired(Bitmap bitmap, File photoFile) throws Exception {
|
|
850
|
+
|
|
851
|
+
ExifInterface exif = new ExifInterface(photoFile.getAbsolutePath());
|
|
852
|
+
|
|
853
|
+
int orientation = exif.getAttributeInt(
|
|
854
|
+
ExifInterface.TAG_ORIENTATION,
|
|
855
|
+
ExifInterface.ORIENTATION_NORMAL
|
|
856
|
+
);
|
|
857
|
+
|
|
858
|
+
Matrix matrix = new Matrix();
|
|
859
|
+
|
|
860
|
+
switch (orientation) {
|
|
861
|
+
case ExifInterface.ORIENTATION_ROTATE_90:
|
|
862
|
+
matrix.postRotate(90);
|
|
863
|
+
break;
|
|
864
|
+
case ExifInterface.ORIENTATION_ROTATE_180:
|
|
865
|
+
matrix.postRotate(180);
|
|
866
|
+
break;
|
|
867
|
+
case ExifInterface.ORIENTATION_ROTATE_270:
|
|
868
|
+
matrix.postRotate(270);
|
|
869
|
+
break;
|
|
870
|
+
default:
|
|
871
|
+
return bitmap;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
Bitmap rotated = Bitmap.createBitmap(
|
|
875
|
+
bitmap,
|
|
876
|
+
0,
|
|
877
|
+
0,
|
|
878
|
+
bitmap.getWidth(),
|
|
879
|
+
bitmap.getHeight(),
|
|
880
|
+
matrix,
|
|
881
|
+
true
|
|
882
|
+
);
|
|
883
|
+
|
|
884
|
+
bitmap.recycle();
|
|
885
|
+
return rotated;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
|
|
845
889
|
|
|
846
890
|
|
|
847
891
|
}
|