@carviz/capacitor-camera-preview 7.2.2 → 7.2.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.
|
@@ -311,8 +311,41 @@ class CameraController: NSObject {
|
|
|
311
311
|
return
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
//
|
|
315
|
-
|
|
314
|
+
// Capture the preview layer content directly - this mimics what the user sees
|
|
315
|
+
DispatchQueue.main.async {
|
|
316
|
+
guard let image = self.capturePreviewLayerAsImage() else {
|
|
317
|
+
completion(nil, CameraControllerError.unknown)
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Apply the same orientation fix as the regular capture function
|
|
322
|
+
let orientationFixedImage = image.fixedOrientation() ?? image
|
|
323
|
+
completion(orientationFixedImage, nil)
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private func capturePreviewLayerAsImage() -> UIImage? {
|
|
328
|
+
// Ensure we're on the main thread
|
|
329
|
+
assert(Thread.isMainThread)
|
|
330
|
+
|
|
331
|
+
// Get the preview layer bounds
|
|
332
|
+
let bounds = previewLayer.bounds
|
|
333
|
+
|
|
334
|
+
// Create a graphics context
|
|
335
|
+
UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.main.scale)
|
|
336
|
+
guard let context = UIGraphicsGetCurrentContext() else {
|
|
337
|
+
UIGraphicsEndImageContext()
|
|
338
|
+
return nil
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Render the preview layer into the context
|
|
342
|
+
previewLayer.render(in: context)
|
|
343
|
+
|
|
344
|
+
// Get the image from the context
|
|
345
|
+
let image = UIGraphicsGetImageFromCurrentImageContext()
|
|
346
|
+
UIGraphicsEndImageContext()
|
|
347
|
+
|
|
348
|
+
return image
|
|
316
349
|
}
|
|
317
350
|
|
|
318
351
|
func getSupportedFlashModes() throws -> [String] {
|
|
@@ -538,44 +571,8 @@ extension CameraController: AVCapturePhotoCaptureDelegate {
|
|
|
538
571
|
|
|
539
572
|
extension CameraController: AVCaptureVideoDataOutputSampleBufferDelegate {
|
|
540
573
|
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
|
|
541
|
-
//
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
// Clear the completion block to avoid capturing multiple frames for one request
|
|
545
|
-
self.sampleBufferCaptureCompletionBlock = nil
|
|
546
|
-
|
|
547
|
-
// Convert sample buffer to UIImage using a more direct approach
|
|
548
|
-
guard let image = self.imageFromSampleBuffer(sampleBuffer) else {
|
|
549
|
-
DispatchQueue.main.async {
|
|
550
|
-
completion(nil, CameraControllerError.unknown)
|
|
551
|
-
}
|
|
552
|
-
return
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
// Call completion on main queue
|
|
556
|
-
DispatchQueue.main.async {
|
|
557
|
-
completion(image, nil)
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
private func imageFromSampleBuffer(_ sampleBuffer: CMSampleBuffer) -> UIImage? {
|
|
562
|
-
guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
|
|
563
|
-
return nil
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
// Use CIImage for YUV to RGB conversion, but ensure we get the full extent
|
|
567
|
-
let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
|
|
568
|
-
let context = CIContext()
|
|
569
|
-
|
|
570
|
-
// Make sure we use the full extent of the image
|
|
571
|
-
let rect = CGRect(x: 0, y: 0, width: ciImage.extent.width, height: ciImage.extent.height)
|
|
572
|
-
|
|
573
|
-
guard let cgImage = context.createCGImage(ciImage, from: rect) else {
|
|
574
|
-
return nil
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// Create UIImage with proper orientation
|
|
578
|
-
return UIImage(cgImage: cgImage, scale: 1.0, orientation: .up)
|
|
574
|
+
// We don't actually need to process video frames anymore since we're using preview layer capture
|
|
575
|
+
// This method is kept for compatibility but does nothing
|
|
579
576
|
}
|
|
580
577
|
}
|
|
581
578
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carviz/capacitor-camera-preview",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.3",
|
|
4
4
|
"description": "Fork of the capacitor-community/camera-preview plugin focusing on high resolution photos without bloating up the code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/plugin.cjs.js",
|