public void stopScanner(string options) { if (canvas != null) { ScannerPage.isClosing = true; Deployment.Current.Dispatcher.BeginInvoke(delegate() { if (scannerPage != null) { BarcodeScannerPage.ScannerPage.cameraDevice.Dispose(); if ((int)ScannerPage.param_OverlayMode == 1) { MWOverlay.removeOverlay(); } else if ((int)ScannerPage.param_OverlayMode == 1) { canvas.Children.Remove(imgOverlay); } (currentPage.FindName("LayoutRoot") as Grid).Children.Remove(canvas); if (flashButton != null) { (currentPage.FindName("LayoutRoot") as Grid).Children.Remove(flashButton); flashButton = null; } scannerPage.stopCamera(); scannerPage = null; canvas = null; videoBrush = null; } }); } }
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) { if (videoBrush == null) { return; } MWOverlay.removeOverlay(); MWOverlay.addOverlay(canvas); fixOrientation(e.Orientation); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); closeScanner = false; isPage = true; if (param_Orientation == SupportedPageOrientation.Landscape) { this.Dispatcher.BeginInvoke((Action)(() => { this.SupportedOrientations = SupportedPageOrientation.Landscape; })); } else if (param_Orientation == SupportedPageOrientation.Portrait) { this.Dispatcher.BeginInvoke((Action)(() => { this.SupportedOrientations = SupportedPageOrientation.Portrait; })); } if (CPU_CORES <= 0) { CPU_CORES = BarcodeHelper.getCPUCores(); } if (param_maxThreads > CPU_CORES) { param_maxThreads = CPU_CORES; } InitializeCamera(CameraSensorLocation.Back); isProcessing = false; resultDisplayed = false; isClosing = false; fixOrientation(Orientation); if ((param_OverlayMode & OverlayMode.OM_MW) > 0) { MWOverlay.addOverlay(canvas); } if ((param_OverlayMode & OverlayMode.OM_IMAGE) > 0) { cameraOverlay.Visibility = System.Windows.Visibility.Visible; } else { cameraOverlay.Visibility = System.Windows.Visibility.Collapsed; } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); if (param_Orientation == SupportedPageOrientation.Landscape) { this.Dispatcher.BeginInvoke((Action)(() => { this.SupportedOrientations = SupportedPageOrientation.Landscape; })); } else if (param_Orientation == SupportedPageOrientation.Portrait) { this.Dispatcher.BeginInvoke((Action)(() => { this.SupportedOrientations = SupportedPageOrientation.Portrait; })); } InitializeCamera(CameraSensorLocation.Back); isProcessing = false; fixOrientation(Orientation); if ((param_OverlayMode & OverlayMode.OM_MW) > 0) { MWOverlay.addOverlay(canvas); } if ((param_OverlayMode & OverlayMode.OM_IMAGE) > 0) { cameraOverlay.Visibility = System.Windows.Visibility.Visible; } else { cameraOverlay.Visibility = System.Windows.Visibility.Collapsed; } }
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e) { if (cameraDevice != null) { try { isProcessing = true; stopCamera(); } catch (Exception e2) { Debug.WriteLine("Camera closing error: " + e2.Message); } } if ((param_OverlayMode & OverlayMode.OM_MW) > 0) { MWOverlay.removeOverlay(); } base.OnNavigatingFrom(e); }
public void startScannerView(string options) { Deployment.Current.Dispatcher.BeginInvoke(delegate() { if (canvas == null) { string[] paramsList = JsonHelper.Deserialize <string[]>(options); mwbScanner = this; kallbackID = paramsList[4]; bool firstTimePageLoad = false; if (currentPage == null) { firstTimePageLoad = true; currentPage = (((PhoneApplicationFrame)Application.Current.RootVisual).Content as PhoneApplicationPage); } var screenWidth = (currentPage.Orientation == PageOrientation.Portrait || currentPage.Orientation == PageOrientation.PortraitUp || currentPage.Orientation == PageOrientation.PortraitDown) ? Application.Current.Host.Content.ActualWidth : Application.Current.Host.Content.ActualHeight; var screenHeight = (currentPage.Orientation == PageOrientation.Landscape || currentPage.Orientation == PageOrientation.LandscapeLeft || currentPage.Orientation == PageOrientation.LandscapeRight) ? Application.Current.Host.Content.ActualWidth : Application.Current.Host.Content.ActualHeight; var pX = Convert.ToInt32(paramsList[0]); var pY = Convert.ToInt32(paramsList[1]); var pWidth = Convert.ToInt32(paramsList[2]); var pHeight = Convert.ToInt32(paramsList[3]); var x = (float)pX / 100 * screenWidth; var y = (float)pY / 100 * screenHeight; width = (float)pWidth / 100 * screenWidth; height = (float)pHeight / 100 * screenHeight; videoBrush = new System.Windows.Media.VideoBrush(); canvas = new Canvas() { Background = videoBrush, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; float heightTmp = (float)height; float widthTmp = (float)width; heightClip = 0; widthClip = 0; float AR = (float)screenHeight / (float)screenWidth; if (width * AR >= height) { heightTmp = (int)(width * AR); heightClip = (float)(heightTmp - height) / 2; } else { widthTmp = (int)(height / AR); widthClip = (float)(widthTmp - width) / 2; } canvas.Width = widthTmp; canvas.Height = heightTmp; RectangleGeometry rg = new RectangleGeometry(); rg.Rect = new System.Windows.Rect(widthClip, heightClip, width, height); canvas.Clip = rg; canvas.Margin = new Thickness(x - widthClip, y - heightClip, 0, 0); if (pX == 0 && pY == 0 && pWidth == 1 && pHeight == 1) { canvas.Visibility = Visibility.Collapsed; } (currentPage.FindName("LayoutRoot") as Grid).Children.Add(canvas); scannerPage = new ScannerPage(); scannerPage.videoBrush = videoBrush; ScannerPage.isPage = false; scannerPage.InitializeCamera(CameraSensorLocation.Back); scannerPage.fixOrientation(currentPage.Orientation); setAutoRect(); if ((int)ScannerPage.param_OverlayMode == 1) { MWOverlay.addOverlay(canvas); } else if ((int)ScannerPage.param_OverlayMode == 2) { imgOverlay = new Image() { Stretch = Stretch.Fill, Width = width, Height = height, Margin = new Thickness(widthClip, heightClip, 0, 0) }; BitmapImage BitImg = new BitmapImage(new Uri("/Plugins/manateeworks-barcodescanner/overlay_mw.png", UriKind.Relative)); imgOverlay.Source = BitImg; canvas.Children.Add(imgOverlay); } if (ScannerPage.param_EnableFlash) { flashButton = new Button() { Width = 70, Height = 70, BorderThickness = new Thickness(0, 0, 0, 0), Margin = new Thickness(x + 5, y + 5, 0, 0), Background = new ImageBrush() { ImageSource = new BitmapImage(new Uri("/Plugins/manateeworks-barcodescanner/flashbuttonoff.png", UriKind.Relative)) }, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top }; flashButton.Click += delegate { scannerPage.flashButton_Click(null, null); }; (currentPage.FindName("LayoutRoot") as Grid).Children.Add(flashButton); } if (firstTimePageLoad) { currentPage.NavigationService.Navigating += delegate { stopScanner(""); }; currentPage.OrientationChanged += delegate { Deployment.Current.Dispatcher.BeginInvoke(delegate() { if (canvas != null) { if ((int)ScannerPage.param_OverlayMode == 1) { MWOverlay.removeOverlay(); } screenWidth = (currentPage.Orientation == PageOrientation.Portrait || currentPage.Orientation == PageOrientation.PortraitUp || currentPage.Orientation == PageOrientation.PortraitDown) ? Application.Current.Host.Content.ActualWidth : Application.Current.Host.Content.ActualHeight; screenHeight = (currentPage.Orientation == PageOrientation.Landscape || currentPage.Orientation == PageOrientation.LandscapeLeft || currentPage.Orientation == PageOrientation.LandscapeRight) ? Application.Current.Host.Content.ActualWidth : Application.Current.Host.Content.ActualHeight; x = (float)pX / 100 * screenWidth; y = (float)pY / 100 * screenHeight; width = (float)pWidth / 100 * screenWidth; height = (float)pHeight / 100 * screenHeight; heightTmp = (float)height; widthTmp = (float)width; heightClip = 0; widthClip = 0; AR = (float)screenHeight / (float)screenWidth; if (width * AR >= height) { heightTmp = (float)(width * AR); heightClip = (float)(heightTmp - height) / 2; } else { widthTmp = (float)(height / AR); widthClip = (float)(widthTmp - width) / 2; } canvas.Width = widthTmp; canvas.Height = heightTmp; rg = new RectangleGeometry(); rg.Rect = new System.Windows.Rect(widthClip, heightClip, width, height); canvas.Clip = rg; canvas.Margin = new Thickness(x - widthClip, y - heightClip, 0, 0); if (flashButton != null) { flashButton.Margin = new Thickness(x + 5, y + 5, 0, 0); } scannerPage.fixOrientation(currentPage.Orientation); setAutoRect(); if ((int)ScannerPage.param_OverlayMode == 1) { Observable .Timer(TimeSpan.FromMilliseconds(100)) .SubscribeOnDispatcher() .Subscribe(_ => { Deployment.Current.Dispatcher.BeginInvoke(delegate() { MWOverlay.addOverlay(canvas); }); }); } else if ((int)ScannerPage.param_OverlayMode == 2) { imgOverlay.Width = width; imgOverlay.Height = height; imgOverlay.Margin = new Thickness(widthClip, heightClip, 0, 0); } } }); }; } } else { setAutoRect(); } }); }