capacitor-camera-module 0.0.36 → 0.0.38
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.
|
@@ -73,6 +73,9 @@ import java.util.concurrent.Executors;
|
|
|
73
73
|
import java.util.concurrent.ExecutorService;
|
|
74
74
|
import java.io.File;
|
|
75
75
|
|
|
76
|
+
import androidx.exifinterface.media.ExifInterface;
|
|
77
|
+
import java.io.FileInputStream;
|
|
78
|
+
|
|
76
79
|
@CapacitorPlugin(
|
|
77
80
|
name = "CameraModule",
|
|
78
81
|
permissions = {
|
|
@@ -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();
|
|
@@ -639,71 +643,69 @@ public class CameraModulePlugin extends Plugin {
|
|
|
639
643
|
@PluginMethod
|
|
640
644
|
public void startBarcodeScan(PluginCall call) {
|
|
641
645
|
|
|
642
|
-
|
|
643
|
-
call.reject("Preview not started");
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
if (getPermissionState("camera") != PermissionState.GRANTED) {
|
|
648
|
-
call.reject("Camera permission not granted");
|
|
649
|
-
return;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
if (cameraProvider == null) {
|
|
653
|
-
call.reject("Camera not initialized");
|
|
654
|
-
return;
|
|
655
|
-
}
|
|
646
|
+
getActivity().runOnUiThread(() -> {
|
|
656
647
|
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
648
|
+
if (previewView == null) {
|
|
649
|
+
call.reject("Preview not started");
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
661
652
|
|
|
662
|
-
|
|
653
|
+
if (getPermissionState("camera") != PermissionState.GRANTED) {
|
|
654
|
+
call.reject("Camera permission not granted");
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
663
657
|
|
|
664
|
-
|
|
658
|
+
if (cameraProvider == null) {
|
|
659
|
+
call.reject("Camera not initialized");
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
665
662
|
|
|
666
|
-
|
|
667
|
-
|
|
663
|
+
if (isScanning) {
|
|
664
|
+
call.reject("Already scanning");
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
668
667
|
|
|
669
|
-
|
|
670
|
-
new ImageAnalysis.Builder()
|
|
671
|
-
.setBackpressureStrategy(
|
|
672
|
-
ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST
|
|
673
|
-
)
|
|
674
|
-
.build();
|
|
668
|
+
barcodeScanner = BarcodeScanning.getClient();
|
|
675
669
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
);
|
|
670
|
+
call.setKeepAlive(true);
|
|
671
|
+
scanCall = call;
|
|
672
|
+
isScanning = true;
|
|
680
673
|
|
|
681
|
-
|
|
674
|
+
imageAnalysis =
|
|
675
|
+
new ImageAnalysis.Builder()
|
|
676
|
+
.setBackpressureStrategy(
|
|
677
|
+
ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST
|
|
678
|
+
)
|
|
679
|
+
.build();
|
|
682
680
|
|
|
683
|
-
|
|
684
|
-
|
|
681
|
+
imageAnalysis.setAnalyzer(
|
|
682
|
+
barcodeExecutor,
|
|
683
|
+
this::processBarcode
|
|
684
|
+
);
|
|
685
685
|
|
|
686
|
-
|
|
687
|
-
new ImageCapture.Builder()
|
|
688
|
-
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
|
689
|
-
.build();
|
|
686
|
+
cameraProvider.unbindAll();
|
|
690
687
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
}
|
|
688
|
+
Preview preview = new Preview.Builder().build();
|
|
689
|
+
preview.setSurfaceProvider(previewView.getSurfaceProvider());
|
|
694
690
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
imageCapture,
|
|
700
|
-
imageAnalysis
|
|
701
|
-
);
|
|
691
|
+
imageCapture =
|
|
692
|
+
new ImageCapture.Builder()
|
|
693
|
+
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
|
694
|
+
.build();
|
|
702
695
|
|
|
703
|
-
|
|
696
|
+
camera = cameraProvider.bindToLifecycle(
|
|
697
|
+
getActivity(),
|
|
698
|
+
cameraSelector,
|
|
699
|
+
preview,
|
|
700
|
+
imageCapture,
|
|
701
|
+
imageAnalysis
|
|
702
|
+
);
|
|
704
703
|
|
|
704
|
+
call.resolve();
|
|
705
|
+
});
|
|
705
706
|
}
|
|
706
707
|
|
|
708
|
+
|
|
707
709
|
private void processBarcode(ImageProxy imageProxy) {
|
|
708
710
|
|
|
709
711
|
if (!isScanning) {
|
|
@@ -842,6 +844,46 @@ public class CameraModulePlugin extends Plugin {
|
|
|
842
844
|
);
|
|
843
845
|
}
|
|
844
846
|
|
|
847
|
+
private Bitmap rotateBitmapIfRequired(Bitmap bitmap, File photoFile) throws Exception {
|
|
848
|
+
|
|
849
|
+
ExifInterface exif = new ExifInterface(photoFile.getAbsolutePath());
|
|
850
|
+
|
|
851
|
+
int orientation = exif.getAttributeInt(
|
|
852
|
+
ExifInterface.TAG_ORIENTATION,
|
|
853
|
+
ExifInterface.ORIENTATION_NORMAL
|
|
854
|
+
);
|
|
855
|
+
|
|
856
|
+
Matrix matrix = new Matrix();
|
|
857
|
+
|
|
858
|
+
switch (orientation) {
|
|
859
|
+
case ExifInterface.ORIENTATION_ROTATE_90:
|
|
860
|
+
matrix.postRotate(90);
|
|
861
|
+
break;
|
|
862
|
+
case ExifInterface.ORIENTATION_ROTATE_180:
|
|
863
|
+
matrix.postRotate(180);
|
|
864
|
+
break;
|
|
865
|
+
case ExifInterface.ORIENTATION_ROTATE_270:
|
|
866
|
+
matrix.postRotate(270);
|
|
867
|
+
break;
|
|
868
|
+
default:
|
|
869
|
+
return bitmap;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
Bitmap rotated = Bitmap.createBitmap(
|
|
873
|
+
bitmap,
|
|
874
|
+
0,
|
|
875
|
+
0,
|
|
876
|
+
bitmap.getWidth(),
|
|
877
|
+
bitmap.getHeight(),
|
|
878
|
+
matrix,
|
|
879
|
+
true
|
|
880
|
+
);
|
|
881
|
+
|
|
882
|
+
bitmap.recycle();
|
|
883
|
+
return rotated;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
|
|
845
887
|
|
|
846
888
|
|
|
847
889
|
}
|