Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions BarcodeScanning.Native.Maui/CameraView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/// <summary>
/// /// Returns the scale factor of the camera preview in Y axis.
/// </summary>
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);
/// <summary>
/// /// Returns the scale factor of the camera preview in X axis.
/// </summary>
public float CameraPreviewScaleX
{
get => (float)GetValue(CameraPreviewScaleXProperty);
set => SetValue(CameraPreviewScaleXProperty, value);
}

public event EventHandler<OnDetectionFinishedEventArg>? OnDetectionFinished;
public event EventHandler<OnImageCapturedEventArg>? OnImageCaptured;

Expand Down
4 changes: 3 additions & 1 deletion BarcodeScanning.Native.Maui/CameraViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public partial class CameraViewHandler : ViewHandler<CameraView, BarcodeView>
[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<CameraView, CameraViewHandler> CameraCommandMapper = new()
Expand Down
12 changes: 11 additions & 1 deletion BarcodeScanning.Native.Maui/Platform/Android/CameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -136,6 +136,7 @@ internal void Start()
UpdateCamera();
UpdateSymbologies();
UpdateTorch();
UpdatePreviewScale();

if (_lifecycleOwner is not null)
_cameraController?.BindToLifecycle(_lifecycleOwner);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions BarcodeScanning.Native.Maui/Platform/MaciOS/CameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ internal void UpdateZoomFactor()
}
}

internal void UpdatePreviewScale()
{
// not supported yet
}

private void DeviceLock(Action action)
{
DispatchQueue.MainQueue.DispatchBarrierAsync(() =>
Expand Down
1 change: 1 addition & 0 deletions BarcodeScanning.Native.Maui/Platform/NET/CameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
3 changes: 2 additions & 1 deletion BarcodeScanning.Test/ScanPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
x:Name="Graphics"
InputTransparent="True"/>

<Grid ColumnDefinitions="*, *, *, *, *, *" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,0.1">
<Grid ColumnDefinitions="*, *, *, *, *, *, *" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,0.1">
<Picker x:Name="Quality" Grid.Column="3" BackgroundColor="Transparent" WidthRequest="45" HeightRequest="45" SelectedIndexChanged="Quality_SelectedIndexChanged"/>

<Button x:Name="BackButton" Grid.Column="0" WidthRequest="50" HeightRequest="50" CornerRadius="25" Clicked="BackButton_Clicked"/>
Expand All @@ -32,6 +32,7 @@
<Button Text="Q" Grid.Column="3" WidthRequest="50" HeightRequest="50" CornerRadius="25" InputTransparent="True"/>
<Button Text="V" Grid.Column="4" WidthRequest="50" HeightRequest="50" CornerRadius="25" Clicked="VibrateButton_Clicked"/>
<Button Text="P" Grid.Column="5" WidthRequest="50" HeightRequest="50" CornerRadius="25" Clicked="PauseButton_Clicked"/>
<Button Text="R" Grid.Column="6" WidthRequest="50" HeightRequest="50" CornerRadius="25" Clicked="RotateButton_Clicked" />
</Grid>
</AbsoluteLayout>

Expand Down
6 changes: 6 additions & 0 deletions BarcodeScanning.Test/ScanPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ private void PauseButton_Clicked(object sender, EventArgs e)
Barcode.PauseScanning = true;
}

private void RotateButton_Clicked(object sender, EventArgs e)
{
Barcode.CameraPreviewScaleY = Barcode.CameraPreviewScaleY * -1;
Barcode.CameraPreviewScaleX = Barcode.CameraPreviewScaleX * -1;
}

private void Quality_SelectedIndexChanged(object sender, EventArgs e)
{
var picker = (Picker)sender;
Expand Down