capacitor-camera-view 1.0.1 → 1.0.2
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.
|
@@ -19,6 +19,7 @@ import androidx.camera.core.ImageCaptureException
|
|
|
19
19
|
import androidx.camera.core.resolutionselector.AspectRatioStrategy
|
|
20
20
|
import androidx.camera.core.resolutionselector.ResolutionSelector
|
|
21
21
|
import androidx.camera.mlkit.vision.MlKitAnalyzer
|
|
22
|
+
import androidx.camera.view.CameraController
|
|
22
23
|
import androidx.camera.view.LifecycleCameraController
|
|
23
24
|
import androidx.camera.view.PreviewView
|
|
24
25
|
import androidx.core.content.ContextCompat
|
|
@@ -125,6 +126,7 @@ class CameraView(plugin: Plugin) {
|
|
|
125
126
|
|
|
126
127
|
/** Capture a photo with the current camera configuration */
|
|
127
128
|
fun capturePhoto(quality: Int, callback: (String?, Exception?) -> Unit) {
|
|
129
|
+
val timeStart = System.currentTimeMillis()
|
|
128
130
|
val controller = this.cameraController
|
|
129
131
|
?: run {
|
|
130
132
|
callback(null, Exception("Camera controller not initialized"))
|
|
@@ -143,6 +145,10 @@ class CameraView(plugin: Plugin) {
|
|
|
143
145
|
cameraExecutor,
|
|
144
146
|
object : ImageCapture.OnImageSavedCallback {
|
|
145
147
|
override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) {
|
|
148
|
+
Log.d(
|
|
149
|
+
TAG,
|
|
150
|
+
"Image stored to temp file in ${System.currentTimeMillis() - timeStart} ms"
|
|
151
|
+
)
|
|
146
152
|
handleImageSaved(tempFile, quality, callback)
|
|
147
153
|
}
|
|
148
154
|
|
|
@@ -172,9 +178,10 @@ class CameraView(plugin: Plugin) {
|
|
|
172
178
|
val startTime = System.currentTimeMillis()
|
|
173
179
|
try {
|
|
174
180
|
val jpegBytes = tempFile.readBytes()
|
|
181
|
+
Log.d(TAG, "Image size : ${jpegBytes.size} bytes")
|
|
175
182
|
val base64String = if (quality == 100) {
|
|
176
183
|
// If quality is 100, return the original JPEG without re-encoding
|
|
177
|
-
Log.d(TAG, "Encoding original JPEG
|
|
184
|
+
Log.d(TAG, "Encoding original JPEG with quality 100")
|
|
178
185
|
Base64.encodeToString(jpegBytes, Base64.NO_WRAP)
|
|
179
186
|
} else {
|
|
180
187
|
// Otherwise, re-encode the JPEG with the specified quality
|
|
@@ -200,12 +207,12 @@ class CameraView(plugin: Plugin) {
|
|
|
200
207
|
|
|
201
208
|
val compressedBytes = compressedFile.readBytes()
|
|
202
209
|
compressedFile.delete()
|
|
210
|
+
Log.d(TAG, "Re-encoded image size: ${compressedBytes.size} bytes")
|
|
203
211
|
Base64.encodeToString(compressedBytes, Base64.NO_WRAP)
|
|
204
212
|
}
|
|
205
|
-
val endTime = System.currentTimeMillis()
|
|
206
213
|
Log.d(
|
|
207
214
|
TAG,
|
|
208
|
-
"Image processing took ${
|
|
215
|
+
"Image processing took ${System.currentTimeMillis() - startTime} ms (quality: $quality)"
|
|
209
216
|
)
|
|
210
217
|
tempFile.delete()
|
|
211
218
|
callback(base64String, null)
|
|
@@ -219,7 +226,7 @@ class CameraView(plugin: Plugin) {
|
|
|
219
226
|
* Capture a frame directly from the preview without using the full photo pipeline which is
|
|
220
227
|
* faster but has lower quality.
|
|
221
228
|
*/
|
|
222
|
-
fun captureSampleFromPreview(quality: Int
|
|
229
|
+
fun captureSampleFromPreview(quality: Int, callback: (String?, Exception?) -> Unit) {
|
|
223
230
|
val previewView =
|
|
224
231
|
this.previewView
|
|
225
232
|
?: run {
|
|
@@ -238,7 +245,7 @@ class CameraView(plugin: Plugin) {
|
|
|
238
245
|
}
|
|
239
246
|
|
|
240
247
|
// Convert bitmap to Base64
|
|
241
|
-
bitmap.compress(Bitmap.CompressFormat.JPEG, quality
|
|
248
|
+
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream)
|
|
242
249
|
val byteArray = outputStream.toByteArray()
|
|
243
250
|
val base64String = Base64.encodeToString(byteArray, Base64.NO_WRAP)
|
|
244
251
|
|
|
@@ -464,10 +471,11 @@ class CameraView(plugin: Plugin) {
|
|
|
464
471
|
// Initialize camera controller
|
|
465
472
|
val controller = LifecycleCameraController(context).apply {
|
|
466
473
|
cameraSelector = currentCameraSelector
|
|
474
|
+
imageCapture = ImageCapture.Builder()
|
|
475
|
+
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
|
476
|
+
.build()
|
|
467
477
|
imageCaptureResolutionSelector = ResolutionSelector.Builder()
|
|
468
|
-
.setAspectRatioStrategy(
|
|
469
|
-
AspectRatioStrategy.RATIO_16_9_FALLBACK_AUTO_STRATEGY
|
|
470
|
-
)
|
|
478
|
+
.setAspectRatioStrategy(AspectRatioStrategy.RATIO_16_9_FALLBACK_AUTO_STRATEGY)
|
|
471
479
|
.build()
|
|
472
480
|
}
|
|
473
481
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.michaelwolz.capacitorcameraview
|
|
2
2
|
|
|
3
3
|
import android.Manifest
|
|
4
|
+
import android.util.Log
|
|
4
5
|
import com.getcapacitor.JSArray
|
|
5
6
|
import com.getcapacitor.JSObject
|
|
6
7
|
import com.getcapacitor.PermissionState
|
|
@@ -73,6 +74,7 @@ class CameraViewPlugin : Plugin() {
|
|
|
73
74
|
|
|
74
75
|
@PluginMethod
|
|
75
76
|
fun capture(call: PluginCall) {
|
|
77
|
+
val timeStart = System.currentTimeMillis();
|
|
76
78
|
val quality = call.getInt("quality") ?: 90
|
|
77
79
|
|
|
78
80
|
if (quality !in 0..100) {
|
|
@@ -86,12 +88,14 @@ class CameraViewPlugin : Plugin() {
|
|
|
86
88
|
photo == null -> call.reject("No image data")
|
|
87
89
|
else -> call.resolve(JSObject().apply { put("photo", photo) })
|
|
88
90
|
}
|
|
91
|
+
Log.d(TAG, "capture took ${System.currentTimeMillis() - timeStart}ms")
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
@PluginMethod
|
|
93
96
|
fun captureSample(call: PluginCall) {
|
|
94
|
-
val
|
|
97
|
+
val timeStart = System.currentTimeMillis();
|
|
98
|
+
val quality = call.getInt("quality") ?: 90
|
|
95
99
|
|
|
96
100
|
if (quality !in 0..100) {
|
|
97
101
|
call.reject("Quality must be between 0 and 100")
|
|
@@ -104,6 +108,7 @@ class CameraViewPlugin : Plugin() {
|
|
|
104
108
|
photo == null -> call.reject("No frame data")
|
|
105
109
|
else -> call.resolve(JSObject().apply { put("photo", photo) })
|
|
106
110
|
}
|
|
111
|
+
Log.d(TAG, "captureSample took ${System.currentTimeMillis() - timeStart}ms")
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
114
|
|
|
@@ -224,4 +229,8 @@ class CameraViewPlugin : Plugin() {
|
|
|
224
229
|
implementation.cleanup()
|
|
225
230
|
super.handleOnDestroy()
|
|
226
231
|
}
|
|
232
|
+
|
|
233
|
+
companion object {
|
|
234
|
+
private const val TAG = "CameraViewPlugin"
|
|
235
|
+
}
|
|
227
236
|
}
|
package/package.json
CHANGED