diff --git a/BarcodeScanning.Native.Maui/CameraView.cs b/BarcodeScanning.Native.Maui/CameraView.cs index 26ba3bb..41bda35 100644 --- a/BarcodeScanning.Native.Maui/CameraView.cs +++ b/BarcodeScanning.Native.Maui/CameraView.cs @@ -321,6 +321,34 @@ public float[] DeviceSwitchZoomFactor set => SetValue(DeviceSwitchZoomFactorProperty, value); } + public static readonly BindableProperty CameraPreviewScaleYProperty = BindableProperty.Create(nameof(CameraPreviewScaleY) + , typeof(float) + , typeof(CameraView) + , 1f + , BindingMode.OneWayToSource); + /// + /// /// Returns the scale factor of the camera preview in Y axis. + /// + public float CameraPreviewScaleY + { + get => (float)GetValue(CameraPreviewScaleYProperty); + set => SetValue(CameraPreviewScaleYProperty, value); + } + + public static readonly BindableProperty CameraPreviewScaleXProperty = BindableProperty.Create(nameof(CameraPreviewScaleX) + , typeof(float) + , typeof(CameraView) + , 1f + , BindingMode.OneWayToSource); + /// + /// /// Returns the scale factor of the camera preview in X axis. + /// + public float CameraPreviewScaleX + { + get => (float)GetValue(CameraPreviewScaleXProperty); + set => SetValue(CameraPreviewScaleXProperty, value); + } + public event EventHandler? OnDetectionFinished; public event EventHandler? OnImageCaptured; diff --git a/BarcodeScanning.Native.Maui/CameraViewHandler.cs b/BarcodeScanning.Native.Maui/CameraViewHandler.cs index 9335bff..871dd14 100644 --- a/BarcodeScanning.Native.Maui/CameraViewHandler.cs +++ b/BarcodeScanning.Native.Maui/CameraViewHandler.cs @@ -17,7 +17,9 @@ public partial class CameraViewHandler : ViewHandler [nameof(CameraView.AimMode)] = (handler, virtualView) => handler._cameraManager?.UpdateAimMode(), [nameof(CameraView.TapToFocusEnabled)] = (handler, virtualView) => handler?._cameraManager?.UpdateTapToFocus(), [nameof(CameraView.RequestZoomFactor)] = (handler, virtualView) => handler?._cameraManager?.UpdateZoomFactor(), - [nameof(CameraView.VibrationOnDetected)] = (handler, virtualView) => handler?._cameraManager?.UpdateVibration() + [nameof(CameraView.VibrationOnDetected)] = (handler, virtualView) => handler?._cameraManager?.UpdateVibration(), + [nameof(CameraView.CameraPreviewScaleY)] = (handler, virtualView) => handler?._cameraManager?.UpdatePreviewScale(), + [nameof(CameraView.CameraPreviewScaleX)] = (handler, virtualView) => handler?._cameraManager?.UpdatePreviewScale(), }; public static readonly CommandMapper CameraCommandMapper = new() diff --git a/BarcodeScanning.Native.Maui/Platform/Android/CameraManager.cs b/BarcodeScanning.Native.Maui/Platform/Android/CameraManager.cs index afdbbdb..318d99b 100644 --- a/BarcodeScanning.Native.Maui/Platform/Android/CameraManager.cs +++ b/BarcodeScanning.Native.Maui/Platform/Android/CameraManager.cs @@ -91,7 +91,7 @@ internal CameraManager(CameraView cameraView, Context context) _previewView.SetBackgroundColor(_cameraView?.BackgroundColor?.ToPlatform() ?? Color.Transparent); _previewView.SetImplementationMode(PreviewView.ImplementationMode.Compatible); _previewView.SetScaleType(PreviewView.ScaleType.FillCenter); - + using var layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); layoutParams.AddRule(LayoutRules.CenterInParent); using var circleBitmap = Bitmap.CreateBitmap(2 * aimRadius, 2 * aimRadius, Bitmap.Config.Argb8888); @@ -136,6 +136,7 @@ internal void Start() UpdateCamera(); UpdateSymbologies(); UpdateTorch(); + UpdatePreviewScale(); if (_lifecycleOwner is not null) _cameraController?.BindToLifecycle(_lifecycleOwner); @@ -236,6 +237,15 @@ internal void UpdateZoomFactor() } } + internal void UpdatePreviewScale() + { + if (_cameraView is not null && _previewView is not null) + { + _previewView.ScaleY = _cameraView.CameraPreviewScaleY; + _previewView.ScaleX = _cameraView.CameraPreviewScaleX; + } + } + internal CoordinateTransform? GetCoordinateTransform(IImageProxy proxy) { var imageOutputTransform = new ImageProxyTransformFactory().GetOutputTransform(proxy); diff --git a/BarcodeScanning.Native.Maui/Platform/MaciOS/CameraManager.cs b/BarcodeScanning.Native.Maui/Platform/MaciOS/CameraManager.cs index 683b9a6..c11c5b4 100644 --- a/BarcodeScanning.Native.Maui/Platform/MaciOS/CameraManager.cs +++ b/BarcodeScanning.Native.Maui/Platform/MaciOS/CameraManager.cs @@ -243,6 +243,11 @@ internal void UpdateZoomFactor() } } + internal void UpdatePreviewScale() + { + // not supported yet + } + private void DeviceLock(Action action) { DispatchQueue.MainQueue.DispatchBarrierAsync(() => diff --git a/BarcodeScanning.Native.Maui/Platform/NET/CameraManager.cs b/BarcodeScanning.Native.Maui/Platform/NET/CameraManager.cs index f0e53d3..cfdd17d 100644 --- a/BarcodeScanning.Native.Maui/Platform/NET/CameraManager.cs +++ b/BarcodeScanning.Native.Maui/Platform/NET/CameraManager.cs @@ -14,6 +14,7 @@ internal class CameraManager : IDisposable internal void UpdateTorch() => throw new NotImplementedException(); internal void UpdateVibration() => throw new NotImplementedException(); internal void UpdateZoomFactor() => throw new NotImplementedException(); + internal void UpdatePreviewScale() => throw new NotImplementedException(); public void Dispose() => throw new NotImplementedException(); } \ No newline at end of file diff --git a/BarcodeScanning.Test/ScanPage.xaml b/BarcodeScanning.Test/ScanPage.xaml index 9464b06..e4ed484 100644 --- a/BarcodeScanning.Test/ScanPage.xaml +++ b/BarcodeScanning.Test/ScanPage.xaml @@ -23,7 +23,7 @@ x:Name="Graphics" InputTransparent="True"/> - +