Redth / ZXing.Net.Mobile

Barcode Scanner for Xamarin.iOS, Xamarin.Android, UWP and Tizen
MIT License
1.07k stars 701 forks source link

AutoFocus and Torch problems #875

Open brzezinol opened 4 years ago

brzezinol commented 4 years ago

Hi, I just finish playing with scanner version 2.4.1 and 3.0.0-beta5. What are the final conclusions:

I using Samsung Galaxsy S6.

Here is my page xaml: <?xml version="1.0" encoding="utf-8" ?> <zxing:ZXingScannerPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms" prism:ViewModelLocator.AutowireViewModel="True" xmlns:zxing="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms" x:Class="xxx.Views.MAG.MAGScanPage" Title="Scanning" DefaultOverlayTopText="Skanowanie" DefaultOverlayBottomText="Skanowanie działa automatycznie" DefaultOverlayShowFlashButton="True"> </zxing:ZXingScannerPage>

DefaultOverlayTopText="Skanowanie" - Not working. Is here any documentation how to setup module in xaml ? When I setup scanner in *.cs overlay shows text but autofocus is not working.

Torch also not enables in production app... ` protected override void OnAppearing() { base.OnAppearing();

        ToggleTorch();

        AutoFocus();
    }

`

Permissions added: `

<uses-permission android:name="android.permission.FLASHLIGHT" />

`

Redth commented 4 years ago

My guess is you're calling ToggleTorch() and AutoFocus() too early and the actual scanner is not setup and running so they are just being ignored.

AutoFocus is kind of a weird one since you shouldn't really need to call that manually (most platform support a continuous auto focus by default). Torch is another matter. Typically you'd provide a button in your overlay for the user to enable the torch. I'm not sure those buttons exist in the default overlay on all the platforms (or for forms). This is something I need to check and improve.

RhomGit commented 4 years ago

Hi there, I just wanted to add that I am using the Sample.Forms.Android project and am having trouble with AutoFocus also (using an actual Samsung Galaxy S8). Opening the scanner seems to not auto focus at all. I have to rotate the device and then it immediately focuses and scans the barcode perfectly.

As a workaround I have added a button to the custom overlay that when Tapped calls AutoFocus(). I have no issue telling our users to do this extra step.

        var refocusButton = new Button
        {
            WidthRequest = 100,
            HeightRequest = 50,
            HorizontalOptions = LayoutOptions.Center,
            VerticalOptions = LayoutOptions.End,
            Text = "Focus",
            Command = new Command(() => zxing.AutoFocus())
        };

        grid.Children.Add(refocusButton);
SmartmanApps commented 4 years ago

Not sure if this is same issue I'm experiencing, but I'll add my input here and can create a new one if needed... Have been using 2.4.1, and tried 3.0.0-beta5 today (in the hope that the problems I was having in 2.4.1 had been fixed). 3.0.0 won't focus for me... well, not until I try doing something else. e.g. whilst it was running and I was wondering why it wasn't focussing, my battery low warning popped up, and all of a sudden it focussed! (I saw a comment somewhere - not sure where now - about someone whose focus didn't work until they used the torch. Thought it was here, but apparently not. Ah! I think it was in one I saw you closed a couple of days ago, so I came to this open one).

I made no code changes, simply upgraded the nuget 2.4.1->3.0.0-beta5. In fact, I thought it so odd I tried it twice (i.e. swapped nugets 4 times) and it's true that ZXing focusses in 2.4.1 but not in 3.0.0-beta5 (except when I did something else). I can see the focus changing slightly, so it seems to be trying, but it simply doesn't come into focus. I haven't used Autofocus() - and as you say who shouldn't be needed anyway - so not sure about where/how to use that as a potential work-around (though as I said, it does appear to be trying to focus, just doesn't succeed).

I just did an experiment - start app, not focussing, switch on bluetooth, comes into focus! Try again, not focussing, switch off bluetooth, comes into focus! There's just something glitchy going on there that it doesn't focus, but doing something else clears it out and it works.

This is on a Note Edge running Android 6.0.1.

Here are some logs (looking at the times, I'd say the "thread started" messages correspond with when I switched the bluetooth on/off. My debug output prefixed by a line of asterisks)...

03-18 16:31:15.584 D/ViewRootImpl( 2958): ViewPostImeInputStage processPointer 0 03-18 16:31:15.669 D/ViewRootImpl( 2958): ViewPostImeInputStage processPointer 1 03-18 16:31:15.694 D/Mono ( 2958): Loading reference 5 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/Good360.dll asmctx DEFAULT, looking for ZXingNetMobile, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null 03-18 16:31:15.694 D/Mono ( 2958): Assembly Ref addref Good360[0xae36d040] -> ZXingNetMobile[0x9c8691e0]: 4 03-18 16:31:15.694 D/Mono ( 2958): Loading reference 3 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/Good360.dll asmctx DEFAULT, looking for ZXing.Net.Mobile.Forms, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null 03-18 16:31:15.694 D/Mono ( 2958): Assembly Ref addref Good360[0xae36d040] -> ZXing.Net.Mobile.Forms[0x9c869180]: 3 [0:] ** starting scan

03-18 16:31:15.699 D/Mono ( 2958): Loading reference 4 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/ZXingNetMobile.dll asmctx DEFAULT, looking for zxing, Version=0.16.5.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60 03-18 16:31:15.699 D/Mono ( 2958): Assembly Ref addref ZXingNetMobile[0x9c8691e0] -> zxing[0x9c869240]: 2 03-18 16:31:15.699 D/Mono ( 2958): Loading reference 4 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/ZXing.Net.Mobile.Forms.dll asmctx DEFAULT, looking for zxing, Version=0.16.5.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60 03-18 16:31:15.699 D/Mono ( 2958): Assembly Ref addref ZXing.Net.Mobile.Forms[0x9c869180] -> zxing[0x9c869240]: 3 03-18 16:31:15.699 D/Mono ( 2958): Loading reference 4 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/Good360.dll asmctx DEFAULT, looking for zxing, Version=0.16.5.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60 03-18 16:31:15.699 D/Mono ( 2958): Assembly Ref addref Good360[0xae36d040] -> zxing[0x9c869240]: 4 [0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText' [0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText' [0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton' [0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText' [0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText' [0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton' 03-18 16:31:15.884 D/Mono ( 2958): Loading reference 7 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/ZXing.Net.Mobile.Forms.dll asmctx DEFAULT, looking for Xamarin.Essentials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 03-18 16:31:15.884 D/Mono ( 2958): Assembly Ref addref ZXing.Net.Mobile.Forms[0x9c869180] -> Xamarin.Essentials[0xb4896f00]: 4 03-18 16:31:15.904 D/Mono ( 2958): Loading reference 5 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/Xamarin.Essentials.dll asmctx DEFAULT, looking for System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e 03-18 16:31:15.904 D/Mono ( 2958): Assembly Ref addref Xamarin.Essentials[0xb4896f00] -> System.Core[0x9c86a2c0]: 7 03-18 16:31:15.924 D/Mono ( 2958): DllImport searching in: 'Internal' ('(null)'). 03-18 16:31:15.924 D/Mono ( 2958): Searching for 'java_interop_jnienv_get_object_field'. 03-18 16:31:15.924 D/Mono ( 2958): Probing 'java_interop_jnienv_get_object_field'. 03-18 16:31:15.929 D/Mono ( 2958): Found as 'java_interop_jnienv_get_object_field'. 03-18 16:31:15.964 D/Mono ( 2958): Loading reference 5 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/ZXingNetMobile.dll asmctx DEFAULT, looking for FastAndroidCamera, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null 03-18 16:31:15.964 D/Mono ( 2958): Assembly Ref addref ZXingNetMobile[0x9c8691e0] -> FastAndroidCamera[0xae36cda0]: 2 03-18 16:31:15.964 D/Mono ( 2958): Loading reference 2 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/FastAndroidCamera.dll asmctx DEFAULT, looking for Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065 03-18 16:31:15.964 D/Mono ( 2958): Assembly Ref addref FastAndroidCamera[0xae36cda0] -> Mono.Android[0x9c869420]: 48 03-18 16:31:16.024 D/TextView( 2958): setTypeface with style : 0 03-18 16:31:16.034 D/Mono ( 2958): Loading reference 2 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/ZXingNetMobile.dll asmctx DEFAULT, looking for System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e 03-18 16:31:16.034 D/Mono ( 2958): Assembly Ref addref ZXingNetMobile[0x9c8691e0] -> System[0x9c869d80]: 12 03-18 16:31:16.039 D/Mono ( 2958): Loading reference 1 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/FastAndroidCamera.dll asmctx DEFAULT, looking for Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065 03-18 16:31:16.039 D/Mono ( 2958): Assembly Ref addref FastAndroidCamera[0xae36cda0] -> Java.Interop[0x9c8694e0]: 12 03-18 16:31:16.049 D/ZXing.Net.Mobile( 2958): Checking Number of cameras... 03-18 16:31:16.054 D/ZXing.Net.Mobile( 2958): Found 2 cameras... 03-18 16:31:16.059 D/ZXing.Net.Mobile( 2958): Found Back Camera, opening... 03-18 16:31:16.094 D/Mono ( 2958): Loading reference 8 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override/ZXingNetMobile.dll asmctx DEFAULT, looking for System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e 03-18 16:31:16.094 D/Mono ( 2958): Assembly Ref addref ZXingNetMobile[0x9c8691e0] -> System.Core[0x9c86a2c0]: 8 03-18 16:31:16.114 D/Mono ( 2958): DllImport searching in: '__Internal' ('(null)'). 03-18 16:31:16.114 D/Mono ( 2958): Searching for 'java_interop_jnienv_call_int_method'. 03-18 16:31:16.114 D/Mono ( 2958): Probing 'java_interop_jnienv_call_int_method'. 03-18 16:31:16.114 D/Mono ( 2958): Found as 'java_interop_jnienv_call_int_method'. 03-18 16:31:16.134 D/ZXing.Net.Mobile( 2958): Selected Resolution: 960x720 03-18 16:31:16.144 D/ZXing.Net.Mobile( 2958): Changing Camera Orientation to: 90 03-18 16:31:16.149 D/Camera ( 2958): app passed NULL surface 03-18 16:31:16.159 D/Mono ( 2958): DllImport searching in: 'Internal' ('(null)'). 03-18 16:31:16.159 D/Mono ( 2958): Searching for 'java_interop_jnienv_get_byte_array_elements'. 03-18 16:31:16.159 D/Mono ( 2958): Probing 'java_interop_jnienv_get_byte_array_elements'. 03-18 16:31:16.159 D/Mono ( 2958): Found as 'java_interop_jnienv_get_byte_array_elements'. 03-18 16:31:16.164 D/Mono ( 2958): DllImport searching in: 'Internal' ('(null)'). 03-18 16:31:16.164 D/Mono ( 2958): Searching for 'java_interop_jnienv_release_byte_array_elements'. 03-18 16:31:16.164 D/Mono ( 2958): Probing 'java_interop_jnienv_release_byte_array_elements'. 03-18 16:31:16.164 D/Mono ( 2958): Found as 'java_interop_jnienv_release_byte_array_elements'. 03-18 16:31:16.894 I/Choreographer( 2958): Skipped 63 frames! The application may be doing too much work on its main thread. 03-18 16:31:16.939 D/Mono ( 2958): Loading reference 3 of /storage/emulated/0/Android/data/com.SmartmanApps.Good360/files/.override__/ZXingNetMobile.dll asmctx DEFAULT, looking for Xamarin.Essentials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 03-18 16:31:16.939 D/Mono ( 2958): Assembly Ref addref ZXingNetMobile[0x9c8691e0] -> Xamarin.Essentials[0xb4896f00]: 5 03-18 16:31:16.974 D/ZXing.Net.Mobile( 2958): Selected Resolution: 960x720 03-18 16:31:16.984 D/ZXing.Net.Mobile( 2958): Changing Camera Orientation to: 90 03-18 16:31:19.004 D/Mono ( 2958): GC_BRIDGE waiting for bridge processing to finish 03-18 16:31:19.004 I/art ( 2958): Starting a blocking GC Explicit 03-18 16:31:19.029 I/art ( 2958): Explicit concurrent mark sweep GC freed 6978(567KB) AllocSpace objects, 1(972KB) LOS objects, 47% free, 17MB/33MB, paused 564us total 24.571ms 03-18 16:31:19.034 D/Mono ( 2958): GC_TAR_BRIDGE bridges 408 objects 414 opaque 1 colors 408 colors-bridged 408 colors-visible 408 xref 1 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.13ms tarjan 0.64ms scc-setup 0.27ms gather-xref 0.02ms xref-setup 0.01ms cleanup 0.19ms 03-18 16:31:19.039 D/Mono ( 2958): GC_BRIDGE: Complete, was running for 33.53ms 03-18 16:31:19.039 D/Mono ( 2958): GC_MAJOR: (LOS overflow) time 45.93ms, stw 46.98ms los size: 4096K in use: 1608K 03-18 16:31:19.039 D/Mono ( 2958): GC_MAJOR_SWEEP: major size: 1776K in use: 825K 03-18 16:31:20.984 D/Mono ( 2958): GC_BRIDGE waiting for bridge processing to finish 03-18 16:31:20.989 I/art ( 2958): Starting a blocking GC Explicit 03-18 16:31:21.019 I/art ( 2958): Explicit concurrent mark sweep GC freed 2941(226KB) AllocSpace objects, 2(1216KB) LOS objects, 49% free, 16MB/32MB, paused 625us total 30.842ms 03-18 16:31:21.024 D/Mono ( 2958): GC_TAR_BRIDGE bridges 173 objects 178 opaque 1 colors 173 colors-bridged 173 colors-visible 173 xref 1 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.37ms tarjan 0.22ms scc-setup 0.14ms gather-xref 0.02ms xref-setup 0.00ms cleanup 0.06ms 03-18 16:31:21.024 D/Mono ( 2958): GC_BRIDGE: Complete, was running for 37.17ms 03-18 16:31:21.024 D/Mono ( 2958): GC_MAJOR: (LOS overflow) time 25.87ms, stw 27.31ms los size: 3072K in use: 805K 03-18 16:31:21.024 D/Mono ( 2958): GC_MAJOR_SWEEP: major size: 1776K in use: 817K Thread started: #7 03-18 16:31:22.744 I/art ( 2958): Starting a blocking GC Explicit 03-18 16:31:22.744 D/Mono ( 2958): GC_BRIDGE waiting for bridge processing to finish 03-18 16:31:22.754 I/art ( 2958): Explicit concurrent mark sweep GC freed 2118(172KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 16MB/32MB, paused 250us total 12.139ms 03-18 16:31:22.759 D/Mono ( 2958): GC_TAR_BRIDGE bridges 117 objects 122 opaque 1 colors 117 colors-bridged 117 colors-visible 117 xref 1 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.07ms tarjan 0.06ms scc-setup 0.08ms gather-xref 0.01ms xref-setup 0.00ms cleanup 0.04ms 03-18 16:31:22.759 D/Mono ( 2958): GC_BRIDGE: Complete, was running for 14.00ms 03-18 16:31:22.759 D/Mono ( 2958): GC_MAJOR: (LOS overflow) time 9.73ms, stw 10.66ms los size: 5120K in use: 2155K 03-18 16:31:22.759 D/Mono ( 2958): GC_MAJOR_SWEEP: major size: 1840K in use: 870K 03-18 16:31:23.654 D/ZXing.Net.Mobile( 2958): Selected Resolution: 960x720 03-18 16:31:23.659 D/ZXing.Net.Mobile( 2958): Changing Camera Orientation to: 90 03-18 16:31:24.324 I/art ( 2958): Starting a blocking GC Explicit 03-18 16:31:24.334 I/art ( 2958): Explicit concurrent mark sweep GC freed 3135(281KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 16MB/32MB, paused 254us total 10.081ms 03-18 16:31:24.334 D/Mono ( 2958): GC_TAR_BRIDGE bridges 142 objects 147 opaque 1 colors 142 colors-bridged 142 colors-visible 142 xref 1 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.24ms tarjan 0.07ms scc-setup 0.04ms gather-xref 0.01ms xref-setup 0.00ms cleanup 0.04ms 03-18 16:31:24.334 D/Mono ( 2958): GC_BRIDGE: Complete, was running for 11.77ms 03-18 16:31:24.334 D/Mono ( 2958): GC_MAJOR: (LOS overflow) time 14.84ms, stw 15.62ms los size: 5120K in use: 2155K 03-18 16:31:24.334 D/Mono ( 2958): GC_MAJOR_SWEEP: major size: 1776K in use: 813K 03-18 16:31:24.389 D/ZXing.Net.Mobile( 2958): Barcode Found [0:] ** Barcode is 9781491987650 03-18 16:31:24.524 D/ZXing.Net.Mobile( 2958): Calling SetPreviewDisplay: null 03-18 16:31:24.524 D/Camera ( 2958): app passed NULL surface 03-18 16:31:25.019 V/ActivityThread( 2958): updateVisibility : ActivityRecord{e0aab97 token=android.os.BinderProxy@4a9ca23 {com.SmartmanApps.Good360/crc64eafc03bf5786a6cc.MainActivity}} show : true 03-18 16:31:26.334 I/Timeline( 2958): Timeline: Activity_idle id: android.os.BinderProxy@4a9ca23 time:1624757 03-18 16:31:29.849 D/ViewRootImpl( 2958): ViewPostImeInputStage processPointer 0 03-18 16:31:29.949 D/ViewRootImpl( 2958): ViewPostImeInputStage processPointer 1 [0:] ** starting scan [0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText' [0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText' [0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton' [0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText' [0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText' [0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton' 03-18 16:31:30.084 D/TextView( 2958): setTypeface with style : 0 03-18 16:31:30.089 D/ZXing.Net.Mobile( 2958): Checking Number of cameras... 03-18 16:31:30.089 D/ZXing.Net.Mobile( 2958): Found 2 cameras... 03-18 16:31:30.089 D/ZXing.Net.Mobile( 2958): Found Back Camera, opening... 03-18 16:31:30.114 D/ZXing.Net.Mobile( 2958): Selected Resolution: 960x720 03-18 16:31:30.119 D/ZXing.Net.Mobile( 2958): Changing Camera Orientation to: 90 03-18 16:31:30.119 D/Camera ( 2958): app passed NULL surface 03-18 16:31:30.799 I/Choreographer( 2958): Skipped 44 frames! The application may be doing too much work on its main thread. 03-18 16:31:30.884 D/ZXing.Net.Mobile( 2958): Selected Resolution: 960x720 03-18 16:31:30.894 D/ZXing.Net.Mobile( 2958): Changing Camera Orientation to: 90 03-18 16:31:32.589 D/Mono ( 2958): GC_BRIDGE waiting for bridge processing to finish 03-18 16:31:32.594 I/art ( 2958): Starting a blocking GC Explicit 03-18 16:31:32.614 I/art ( 2958): Explicit concurrent mark sweep GC freed 5960(499KB) AllocSpace objects, 5(4MB) LOS objects, 49% free, 16MB/32MB, paused 559us total 22.638ms 03-18 16:31:32.619 D/Mono ( 2958): GC_TAR_BRIDGE bridges 217 objects 947 opaque 320 colors 219 colors-bridged 217 colors-visible 217 xref 3 cache-hit 0 cache-semihit 0 cache-miss 2 setup 0.16ms tarjan 1.80ms scc-setup 0.16ms gather-xref 0.02ms xref-setup 0.01ms cleanup 0.09ms 03-18 16:31:32.619 D/Mono ( 2958): GC_BRIDGE: Complete, was running for 27.65ms 03-18 16:31:32.619 D/Mono ( 2958): GC_MAJOR: (LOS overflow) time 30.54ms, stw 31.51ms los size: 4096K in use: 1480K 03-18 16:31:32.619 D/Mono ( 2958): GC_MAJOR_SWEEP: major size: 1856K in use: 870K Thread started: #8 03-18 16:31:34.269 I/art ( 2958): Starting a blocking GC Explicit 03-18 16:31:34.279 D/Mono ( 2958): GC_BRIDGE waiting for bridge processing to finish 03-18 16:31:34.279 I/art ( 2958): Explicit concurrent mark sweep GC freed 3227(246KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 16MB/32MB, paused 258us total 12.523ms 03-18 16:31:34.284 D/Mono ( 2958): GC_TAR_BRIDGE bridges 142 objects 147 opaque 1 colors 142 colors-bridged 142 colors-visible 142 xref 1 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.05ms tarjan 0.05ms scc-setup 0.06ms gather-xref 0.01ms xref-setup 0.00ms cleanup 0.04ms 03-18 16:31:34.284 D/Mono ( 2958): GC_BRIDGE: Complete, was running for 14.59ms 03-18 16:31:34.284 D/Mono ( 2958): GC_MAJOR: (LOS overflow) time 9.39ms, stw 15.41ms los size: 3072K in use: 805K 03-18 16:31:34.284 D/Mono ( 2958): GC_MAJOR_SWEEP: major size: 1856K in use: 825K 03-18 16:31:34.869 D/ZXing.Net.Mobile( 2958): Selected Resolution: 960x720 03-18 16:31:34.884 D/ZXing.Net.Mobile( 2958): Changing Camera Orientation to: 90 03-18 16:31:35.624 D/ZXing.Net.Mobile( 2958): Barcode Found [0:] ** Barcode is 9781491987650 03-18 16:31:35.689 D/ZXing.Net.Mobile( 2958): Calling SetPreviewDisplay: null 03-18 16:31:35.689 D/Camera ( 2958): app passed NULL surface

brzezinol commented 4 years ago

My guess is you're calling ToggleTorch() and AutoFocus() too early and the actual scanner is not setup and running so they are just being ignored.

Is there any other way to run ToggleTorch in correct moment? I don't see any scanner event that tells me that all is initialized.


Code below resolve torch problem. `

protected override async void OnAppearing() { base.OnAppearing();

        await Task.Delay(1000).ContinueWith((t) =>
        {
            Device.BeginInvokeOnMainThread(delegate
            {
                ToggleTorch();
            });
        }).ConfigureAwait(true);
    }

`

mourke commented 4 years ago

My guess is you're calling ToggleTorch() and AutoFocus() too early and the actual scanner is not setup and running so they are just being ignored.

Is there any other way to run ToggleTorch in correct moment? I don't see any scanner event that tells me that all is initialized.

Code below resolve torch problem. `

protected override async void OnAppearing() { base.OnAppearing();

        await Task.Delay(1000).ContinueWith((t) =>
        {
            Device.BeginInvokeOnMainThread(delegate
            {
                ToggleTorch();
            });
        }).ConfigureAwait(true);
    }

`

That's really really bad. If this enhancement is implemented you'll get an event when everything is set up. What you're doing right now will break on slow devices or just at any time on a fast device having a bad day.

mduchev commented 4 years ago

I can confirm that I cannot get the Torch to work in beta5. In betas 4 - it was working flawlessly. I tried invoking it explicitly on the main thread but it didn't help. The scanner has been fully loaded when I try - I am opening the page, waiting a few seconds, the scanner starts scanning, but when I click on the torch icon and call ToggleTorch, nothing happens...

onurhazar commented 4 years ago

Same problem here, zxing's torch is not working on iOS 13 (package beta 5). Scanner is already initialized, I put a torch button on the custom overlay view which doesn't work right now.

universaldata-eu commented 4 years ago

any news on this? just tried the forms samples and on android autofocus isn't working. as mentioned by RhomGit after rotating the device autofocus works.

satyamgupta0202 commented 3 years ago

Can we enable Torch/Flashlight while scanning using GOOGLE vision AP I!!!

mcfoi commented 3 years ago

I can confirm that I cannot get the Torch to work in beta5. In betas 4 - it was working flawlessly. I tried invoking it explicitly on the main thread but it didn't help. The scanner has been fully loaded when I try - I am opening the page, waiting a few seconds, the scanner starts scanning, but when I click on the torch icon and call ToggleTorch, nothing happens...

I can confirm that v.3.0.0-beta4 can toggle torch on Android 11 and iOS 14.5 while v.3.1.0-beta5 DOES NOT

volkan-akkus-tr commented 2 years ago

Maybe, don't use a ScannerPage. Use their MobileBarcodeScanner. As Igor Kravchenko stated at https://stackoverflow.com/a/66296505/20395535

ZXing.Mobile.MobileBarcodeScanner scanner = new();
ZXing.Result result = await scanner.Scan().ConfigureAwait(false);

if (result != null && !string.IsNullOrWhiteSpace(result.Text))
{
    // result.Text is ready.
}

Kudos to Igor.