Redth / ZXing.Net.Maui

Barcode Scanning for MAUI?
MIT License
481 stars 153 forks source link

Set CameraBarcodeReaderView Heigth #4

Open viniciusverasdossantos opened 3 years ago

viniciusverasdossantos commented 3 years ago

I need to have a ListView and the barcode reader below it so that upon detecting it will add the product to the list. I was unable to resize CameraBarcodeReaderView. Is there a possibility?

julianadormon commented 2 years ago

Yes please, this does not seem to be responding to HeightRequested.

Filskov-IT commented 2 years ago

Yes HeightRequest isn't working properly. It does not properly scale to layouts either. Would love a fix for this

pyramid-johng commented 1 year ago

Seems to be a chronic bug, and i saw a proposed fix in a different ticket. Please give this some attention.

Pantheas commented 9 months ago

Is this happening only on Android for you guys? I am probably facing the same issue, however the sizing works fine on iOS for me.

gentledepp commented 6 months ago

There seems to be an issue with the PreviewView.

I easily managed to reproduce this issue with the sample project "BigIslandBarcode" by simply putting the CameraBarcodeReaderView into the first grid row (as opposed as letting it spana cross the total view)

<Grid RowDefinitions="1*,3*,1*">

        <zxing:CameraBarcodeReaderView
-           Grid.Row="0" Grid.RowSpan="3"
+           Grid.Row="1"
            x:Name="barcodeView"
            BarcodesDetected="BarcodesDetected"
             />

You can find the repro here

When the CameraManager.android.cs creates the native view (PreviewView) its ScaleType is set to FillCenter https://developer.android.com/media/camera/camerax/preview?hl=en#scale-type

This should be fine, since it should just fill the available space of the PreviewView with the image data. However, it does not:

image

Now, a simple change of mine was to CameraManager.android.cs CreateNativeView and changed the ScaleType to FitCenter. Now the height is respected, but the image does not stretch to the maximum available width anymore:

image

So: Is this an AndroidX bug, or MAUI related?

christianrr commented 5 months ago

I get it to work with the following handler override

protected override PreviewView CreatePlatformView()
    {
        var result = base.CreatePlatformView();
        result.SetScaleType(PreviewView.ScaleType.FillCenter);
        result.SetClipChildren(true);
        result.SetClipToPadding(true);
        result.ClipToOutline = true;
        return result;
    }
Jabbah76 commented 3 months ago

I have been able to work around this by wrapping the CameraBarcodeReaderView inside a (transparent) Frame.