Windows Phone 8 demo client

Dec 19, 2012 at 6:41 PM
Edited Dec 20, 2012 at 6:53 AM

 

Anyone who has demo client for windows phone 8,  in the source repository we have it for WP7, which I am unable to use it in WP8, as there were lot of changes to the camera, media features in WP8.

Thanks

Coordinator
Dec 19, 2012 at 7:33 PM

I'm validating a wp8 demo from another user at the moment. I will add it to the repository. But I'm not sure when I can finish my work. Hopefully before christmas.

Dec 20, 2012 at 4:14 AM

That would be great.!

I am trying to convert this snippet to work with WP8... 

Finding equivalent classes to replace for Windows.Media.Capture.CameraCaptureUI, BitmapImage, WriteableBitmap......  any clues would be great.. 

           Windows.Media.Capture.CameraCaptureUI ccu = new Windows.Media.Capture.CameraCaptureUI();
            ccu.PhotoSettings.Format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.Jpeg;
            ccu.PhotoSettings.MaxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.HighestAvailable;
            Windows.Storage.StorageFile x = await ccu.CaptureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.Photo);
            if (x != null)
            {
                ZXing.BarcodeReader br = new ZXing.BarcodeReader();
                WriteableBitmap wrb;
                BitmapImage img = new BitmapImage();
                img.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                using (IRandomAccessStream fileStream = await x.OpenAsync(FileAccessMode.Read))
                {
                    //fileStream.
                    wrb = await BitmapFactory.New(1, 1).FromStream(fileStream);
                }
                var res = br.Decode(wrb);
                testImage.Source = wrb;
           }

 

 

Coordinator
Dec 21, 2012 at 12:39 PM

I tested the Windows Phone 7 demo. The code compiles without problems with a WP8 project.

I added a Windows Phone 8 demo to the source code repository. It is mainly a copy of the WP7 demo.

Dec 25, 2012 at 7:18 AM

Thanks Mic...!

I am testing that in Nokia Lumia 920, but it is not detecting any barcodes.... I also ran the WP7 sample with another Nokia WP7, it did not detect either...

 

 

Dec 25, 2012 at 4:45 PM

Mic.....its working awesome... I have to hold the barcode min of 6" inches from the camera....

Coordinator
Dec 28, 2012 at 7:08 PM

The sample isn't perfect. Continues focus is missing. Scanning is only done via the preview buffer.
I can't make a better sample because I don't have a WP7 or WP8 device. The emulator doesn't support a webcam.

Btw. my name is Michael. :)

Dec 31, 2012 at 12:24 AM
Edited Dec 31, 2012 at 12:51 AM

This sample doesn't work that well for me. I'm using a Nokia 920 too but I can't get a clear enough image of a barcode close up. When I half-press the camera button, the image momentarily goes into focus but then blurs out again (even though I don't release the camera button). I get the same behaviour with the Basic camera SDK sample. Could be a problem with my phone though. I'm having a play with PhotoCaptureDevice at the moment as this seems to offer more control.

Dec 31, 2012 at 2:45 PM

I was porting sources to Phone 8 using VS2012 and it runs fine on virtual machines, but i think that autofocus must be handled to get optimal results in any hardware.

cam.AutoFocusCompleted += new EventHandler<CameraOperationCompletedEventArgs>(cam_AutoFocusCompleted);
if (cam.IsFocusSupported == true)
        {
            //Focus when a capture is not in progress.
            try
            {
                cam.Focus();
            }
            catch (Exception focusError)
            {
                // Cannot focus when a capture is in progress.
             }
        }

this also can be done at low level. More info:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202964(v=vs.105).aspx#BKMK_InitiatingAutoFocus
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207808(v=vs.105).aspx

Jan 2, 2013 at 5:52 AM
Edited Jan 2, 2013 at 5:56 AM

Michael...  I am having Lumina 920 and it only takes 3-4 seconds max to decode the barcode......  I made the camera to focus repeatedly(no need to press camera button) by calling the camera.focus() just before scanning the preview buffer, so that it continuously scan and decode the barcode.

now, I am working on an issue, where the viewfinder/camera is not working properly(getting blank screen/ sometimes full green screen) when navigated to this page by pressing back button, however it works fine when the page is newly called.

Coordinator
Jan 2, 2013 at 8:53 PM

I think the focus should not initiated directly before scanning the preview buffer. In my opinion the call to the camera.focus() should be done periodically.
And when the AutoFocusCompleted event fires the preview buffer should be scanned. I changed the method from the sample a little bit.
I can't test it but it builds without errors.

      private void CameraButton_Click(object sender, RoutedEventArgs e)
      {
         if (photoCamera == null)
         {
            photoCamera = new PhotoCamera();
            photoCamera.Initialized += OnPhotoCameraInitialized;
            previewVideo.SetSource(photoCamera);

            CameraButtons.ShutterKeyHalfPressed += (o, arg) => photoCamera.Focus();
         }

         if (timer == null)
         {
            timer = new DispatcherTimer {Interval = TimeSpan.FromMilliseconds(500)};
            if (photoCamera.IsFocusSupported)
            {
               photoCamera.AutoFocusCompleted += (o, arg) => { if (arg.Succeeded) ScanPreviewBuffer(); };
               timer.Tick += (o, arg) => { try { photoCamera.Focus(); } catch (Exception ) { } };
            }
            else
            {
               timer.Tick += (o, arg) => ScanPreviewBuffer();
            }
         }

         BarcodeImage.Visibility = System.Windows.Visibility.Collapsed;
         previewRect.Visibility = System.Windows.Visibility.Visible;
         timer.Start();
      }
Another enhancement could be the use of a captured image after autofocus instead of the preview buffer. Capturing is done with a higher resolution.

 

Apr 16, 2013 at 11:04 PM
I am trying to use demo client on lumia 920 and it does not do anything. Appreciate if someone could help me.

Thanks
Coordinator
Apr 21, 2013 at 6:21 PM
There is a new demo client available in the patch section (source code -> patches).
Please try it out. If it doesn't work please describe more in detail what you tried out.
Perhaps you have a stack trace or something similar.
Apr 21, 2013 at 11:28 PM
micjahn wrote:
There is a new demo client available in the patch section (source code -> patches).
Please try it out. If it doesn't work please describe more in detail what you tried out.
Perhaps you have a stack trace or something similar.
Micheal I downloaded from source code-> patches and compiled the solution and deployed it to Nokia Lumia 920. I tried to scan Macys coupons (code 128) and XBOX proof of purchase code (UPC-A) both did not work. Appreciate your help.

Thanks
Coordinator
Apr 23, 2013 at 8:14 PM
My main problem is that I don't have a testing device. Hopefully some other users can help you more.
Try to ask directly the two contributors which uploaded the new WP8 demo clients in the patches section.
Apr 24, 2013 at 3:54 AM
There is a slight discrepancy in the new WP8 demo. It successfully interprets one barcode then usually won't focus again. To fix this, at the end of ReaderOnResultFound in ScanFromCameraFeed you need to add the line
Dispatcher.BeginInvoke(() => _photoCamera.Focus());
in order to kickstart the focusing process after the first successful read.

I am curious why the timer is even needed. I think it would give better results if we just did a
ScanPreviewBuffer();
At every call to the PhotoCameraOnAutoFocusCompleted handler. Right now we are hoping the timer is fired while the camera is in focus. I will try that idea tomorrow.
Developer
Apr 24, 2013 at 5:17 PM
I just updated the Windows Phone 8 DemoClient through your requirements. Thanks a lot guys! :)
Apr 25, 2013 at 3:35 PM
fabianhenzler wrote:
I just updated the Windows Phone 8 DemoClient through your requirements. Thanks a lot guys! :)
Thank You Fab and Socttgs.

The newly added client is working on my lumia 920. I will do little more testing and see how its working for other codes. I have to add that for code type 128 its little bit inconsistent.
Developer
Jun 3, 2013 at 7:01 PM
simplecartoon wrote:
fabianhenzler wrote:
I just updated the Windows Phone 8 DemoClient through your requirements. Thanks a lot guys! :)
Thank You Fab and Socttgs.

The newly added client is working on my lumia 920. I will do little more testing and see how its working for other codes. I have to add that for code type 128 its little bit inconsistent.
any progress in the testing @simplecartoon?
Jul 1, 2013 at 11:34 PM
fabianhenzler wrote:
simplecartoon wrote:
fabianhenzler wrote:
I just updated the Windows Phone 8 DemoClient through your requirements. Thanks a lot guys! :)
Thank You Fab and Socttgs.

The newly added client is working on my lumia 920. I will do little more testing and see how its working for other codes. I have to add that for code type 128 its little bit inconsistent.
any progress in the testing @simplecartoon?
It did work for me 70% of the time for code type 128 (The code base was latest on April 25th. it does not include any latest changes). I did not concentrate on other code types at that point in time. Thank You
Oct 7, 2013 at 3:01 PM
durai123 wrote:
Michael...  I am having Lumina 920 and it only takes 3-4 seconds max to decode the barcode......  I made the camera to focus repeatedly(no need to press camera button) by calling the camera.focus() just before scanning the preview buffer, so that it continuously scan and decode the barcode. now, I am working on an issue, where the viewfinder/camera is not working properly(getting blank screen/ sometimes full green screen) when navigated to this page by pressing back button, however it works fine when the page is newly called.
I have the same problem...
When i scan a qr it's all ok... i navigate in another page and all is good..
but when i press the button BACK sometimes appears a green screen...
I don't understand why!?!?!

Someone can help me please
public MainPage()
        {
            InitializeComponent();
            /* CHECKING CONNECTION STATUS */
            bool isConnected = NetworkInterface.GetIsNetworkAvailable();
            if (!isConnected)
            {
                MessageBox.Show("No internet connection", MessageBoxButton.OK);
                Microsoft.Xna.Framework.Game game = new Microsoft.Xna.Framework.Game();
                game.Exit(); 
            }

            //reading value
            if (IsolatedStorageSettings.ApplicationSettings.Contains("idDevice"))
            {
                idDevice = (string)IsolatedStorageSettings.ApplicationSettings["idDevice"];
            }   
            else
            {
                //insert
                Random random = new Random();
                var duration = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0);
                long ticks = (long)duration.TotalSeconds;

                idDevice = ticks.ToString() + "-" + random.Next(1, 2000000001).ToString();
                IsolatedStorageSettings.ApplicationSettings.Add("idDevice", idDevice);
                IsolatedStorageSettings.ApplicationSettings.Save();
            }

            _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(2) };
            GameTimer gameTimer = new GameTimer();
            gameTimer.UpdateInterval = TimeSpan.FromMilliseconds(33);

            // Call FrameworkDispatcher.Update to update the XNA Framework internals.
            gameTimer.Update += delegate { try { FrameworkDispatcher.Update(); } catch { } };

            // Start the GameTimer running.

            if (Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Playing || Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Paused)
            {
                if (MessageBox.Show("Media is currently playing, do you want to stop it?", "Stop Player", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    try
                    {
                        gameTimer.Stop();
                        Microsoft.Xna.Framework.Media.MediaPlayer.Stop();
                        AudioPlayerS.Source = new Uri("/audioProva.mp3", UriKind.Relative);
                    }
                    catch { }
                }
                else
                {
                    Microsoft.Xna.Framework.Game game = new Microsoft.Xna.Framework.Game();
                    game.Exit(); 
                }  
                   
           }
            
            // Prime the pump or we'll get an exception.
            FrameworkDispatcher.Update();
        }


        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _photoCamera = new PhotoCamera();
            _photoCamera.Initialized += OnPhotoCameraInitialized;
            _previewVideo.SetSource(_photoCamera);
            
            //CameraButtons.ShutterKeyHalfPressed += (o, arg) => _photoCamera.Focus();
            try
            {
                if (_photoCamera.IsFocusSupported)
                {
                    _timer.Tick += (o, arg) => { try { _photoCamera.FlashMode = FlashMode.Off; _photoCamera.Focus(); } catch (Exception) { } };
                    _photoCamera.AutoFocusCompleted += (o, arg) => { if (arg.Succeeded) ScanPreviewBuffer(); };
                }
                else
                {
                    _timer.Tick += (o, arg) => ScanPreviewBuffer();
                }
            }
            catch
            {
                _timer.Tick += (o, arg) => ScanPreviewBuffer();
            }
            base.OnNavigatedTo(e);
        }

        private void OnPhotoCameraInitialized(object sender, CameraOperationCompletedEventArgs e)
        {
            int width = Convert.ToInt32(_photoCamera.PreviewResolution.Width);
            int height = Convert.ToInt32(_photoCamera.PreviewResolution.Height);

            _luminance = new PhotoCameraLuminanceSource(width, height);
            _reader = new QRCodeReader();

            Dispatcher.BeginInvoke(() =>
            {
                _timer.Start();
                _previewTransform.Rotation = _photoCamera.Orientation; 
            });
        }

       
        private void ScanPreviewBuffer()
        {
            
            try
            {
                _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
                var binarizer = new HybridBinarizer(_luminance);
                var binBitmap = new BinaryBitmap(binarizer);
                var result = _reader.decode(binBitmap);
                Dispatcher.BeginInvoke(() => CheckQr(result.Text));
            }
            catch
            {
            }
        }
       
        private void CheckQr(string link)
        {
            if (IsValidHttpUri(link) == false)
            {
                MessageBox.Show("error", MessageBoxButton.OK);
                return;
            }
            else
            {
                _timer.Stop();
                try
                {
                    _photoCamera.CancelFocus();
                }
                catch
                {
                }
                NavigationService.Navigate(new Uri("/reader.xaml?linkQr=" + link, UriKind.Relative));
            }
        }
When i come back from reader.xaml appear the green screen
Developer
Oct 8, 2013 at 12:04 PM
Hi,

did you try to Dispose() the PhotoCamera in the OnNavigatedFrom?
Oct 8, 2013 at 12:27 PM
thank you @fabianhenzler
this seems to work correctly!