@capgo/camera-preview 7.4.0-alpha.0 → 7.4.0-alpha.3
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.
|
@@ -1040,12 +1040,40 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1040
1040
|
saveImageToGallery(bytes);
|
|
1041
1041
|
}
|
|
1042
1042
|
|
|
1043
|
-
String
|
|
1043
|
+
String resultValue;
|
|
1044
|
+
boolean returnFileUri =
|
|
1045
|
+
sessionConfig != null && sessionConfig.isStoreToFile();
|
|
1046
|
+
if (returnFileUri) {
|
|
1047
|
+
// Persist processed image to a file and return its URI to avoid heavy base64 bridging
|
|
1048
|
+
try {
|
|
1049
|
+
String fileName =
|
|
1050
|
+
"cpcp_" +
|
|
1051
|
+
new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(
|
|
1052
|
+
new java.util.Date()
|
|
1053
|
+
) +
|
|
1054
|
+
".jpg";
|
|
1055
|
+
File outDir = context.getCacheDir();
|
|
1056
|
+
File outFile = new File(outDir, fileName);
|
|
1057
|
+
FileOutputStream outFos = new FileOutputStream(outFile);
|
|
1058
|
+
outFos.write(bytes);
|
|
1059
|
+
outFos.close();
|
|
1060
|
+
|
|
1061
|
+
// Return a file path; apps can convert via Capacitor.convertFileSrc on JS side
|
|
1062
|
+
resultValue = outFile.getAbsolutePath();
|
|
1063
|
+
} catch (IOException ioEx) {
|
|
1064
|
+
Log.e(TAG, "capturePhoto: Failed to write image file", ioEx);
|
|
1065
|
+
// Fallback to base64 if file write fails
|
|
1066
|
+
resultValue = Base64.encodeToString(bytes, Base64.NO_WRAP);
|
|
1067
|
+
}
|
|
1068
|
+
} else {
|
|
1069
|
+
// Backward-compatible behavior
|
|
1070
|
+
resultValue = Base64.encodeToString(bytes, Base64.NO_WRAP);
|
|
1071
|
+
}
|
|
1044
1072
|
|
|
1045
1073
|
tempFile.delete();
|
|
1046
1074
|
|
|
1047
1075
|
if (listener != null) {
|
|
1048
|
-
listener.onPictureTaken(
|
|
1076
|
+
listener.onPictureTaken(resultValue, exifData);
|
|
1049
1077
|
}
|
|
1050
1078
|
} catch (Exception e) {
|
|
1051
1079
|
Log.e(TAG, "capturePhoto: Error processing image", e);
|
|
@@ -68,7 +68,7 @@ extension CameraController {
|
|
|
68
68
|
discoverAndConfigureCameras()
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
private func discoverAndConfigureCameras() {
|
|
72
72
|
let deviceTypes: [AVCaptureDevice.DeviceType] = [
|
|
73
73
|
.builtInWideAngleCamera,
|
|
74
74
|
.builtInUltraWideCamera,
|
|
@@ -82,8 +82,6 @@ extension CameraController {
|
|
|
82
82
|
let session = AVCaptureDevice.DiscoverySession(deviceTypes: deviceTypes, mediaType: AVMediaType.video, position: .unspecified)
|
|
83
83
|
let cameras = session.devices.compactMap { $0 }
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
85
|
// Store all discovered devices for fast lookup later
|
|
88
86
|
self.allDiscoveredDevices = cameras
|
|
89
87
|
|
|
@@ -94,7 +92,7 @@ extension CameraController {
|
|
|
94
92
|
|
|
95
93
|
}
|
|
96
94
|
|
|
97
|
-
|
|
95
|
+
// Set front camera (usually just one option)
|
|
98
96
|
self.frontCamera = cameras.first(where: { $0.position == .front })
|
|
99
97
|
|
|
100
98
|
// Find rear camera - prefer tripleCamera for multi-lens support
|
|
@@ -740,8 +738,6 @@ extension CameraController {
|
|
|
740
738
|
|
|
741
739
|
}
|
|
742
740
|
|
|
743
|
-
|
|
744
|
-
|
|
745
741
|
// Create the cropped image
|
|
746
742
|
guard let cgImage = image.cgImage,
|
|
747
743
|
let croppedCGImage = cgImage.cropping(to: cropRect) else {
|
|
@@ -751,7 +747,6 @@ extension CameraController {
|
|
|
751
747
|
|
|
752
748
|
let result = UIImage(cgImage: croppedCGImage, scale: image.scale, orientation: image.imageOrientation)
|
|
753
749
|
|
|
754
|
-
|
|
755
750
|
return result
|
|
756
751
|
}
|
|
757
752
|
|