private static void checkChange()
        {
            if (lineLayer == null || viewportLayer == null)
            {
                return;
            }


            Windows.Foundation.Rect frame = BarcodeHelper.MWBgetScanningRect(0);
            int orientation = BarcodeLib.Scanner.MWBgetDirection();

            if (orientation != lastOrientation || frame.Left != lastLeft || frame.Top != lastTop || frame.Width != lastWidth || frame.Height != lastHeight)
            {
                updateOverlay();
            }

            if (lastBLinkingSpeed != blinkingSpeed)
            {
                removeAnimation();
                addAnimation();
            }

            if (isBlinkingLineVisible != (lineLayer.Visibility == Visibility.Visible))
            {
                updateOverlay();
            }

            if (isViewportVisible != (viewportLayer.Visibility == Visibility.Visible))
            {
                updateOverlay();
            }

            lastOrientation   = orientation;
            lastLeft          = (float)frame.Left;
            lastTop           = (float)frame.Top;
            lastWidth         = (float)frame.Width;
            lastHeight        = (float)frame.Height;
            lastBLinkingSpeed = blinkingSpeed;
        }
        private static void updateOverlay()
        {
            Windows.Foundation.Rect unionRect = BarcodeHelper.MWBgetScanningRect(0);
            int orientation = BarcodeLib.Scanner.MWBgetDirection();

            int width  = (int)currentCanvas.Width;
            int height = (int)currentCanvas.Height;

            float canvasAR = (float)height / width;
            int   left     = 0;
            int   top      = 0;

            if (canvasAR > cameraAR)
            {
                height = (int)(cameraAR * width);
                top    = ((int)currentCanvas.Height - height) / 2;
            }
            else
            {
                width = (int)(height / cameraAR);
                left  = ((int)currentCanvas.Width - width) / 2;
            }

            if (width <= 0)
            {
                width = 800;
            }

            if (height <= 0)
            {
                height = 480;
            }


            int rectLeft   = (int)((float)unionRect.Left * width / 100.0) + left;
            int rectTop    = (int)((float)unionRect.Top * height / 100.0) + top;
            int rectWidth  = (int)((float)unionRect.Width * width / 100.0);
            int rectHeight = (int)((float)unionRect.Height * height / 100.0);
            int rectRight  = (int)((float)unionRect.Right * width / 100.0) + left;
            int rectBottom = (int)((float)unionRect.Bottom * height / 100.0) + top;

            if (isViewportVisible)
            {
                viewportLayer.Visibility = Visibility.Visible;

                var bitmapviewport = new WriteableBitmap((int)currentCanvas.Width, (int)currentCanvas.Height);
                bitmapviewport.FillRectangle(0, 0, (int)currentCanvas.Width, (int)currentCanvas.Height, colorFromAlphaAndInt(viewportAlpha, 0));
                int lineWidth2 = (int)(viewportLineWidth / 2.0);

                bitmapviewport.FillRectangle(rectLeft - lineWidth2, rectTop - lineWidth2, rectRight + lineWidth2, rectBottom + lineWidth2, colorFromAlphaAndInt(viewportLineAlpha, viewportLineColor));
                bitmapviewport.FillRectangle(rectLeft, rectTop, rectRight, rectBottom, Color.FromArgb(0, 0, 0, 0));



                viewportLayer.Source = bitmapviewport;
            }
            else
            {
                viewportLayer.Visibility = Visibility.Collapsed;
            }


            if (isBlinkingLineVisible)
            {
                lineLayer.Visibility = Visibility.Visible;

                addAnimation();



                var bitmapLine = new WriteableBitmap((int)currentCanvas.Width, (int)currentCanvas.Height);
                int lineWidth2 = (int)(blinkingLineWidth / 2.0);
                int widthAddon = 0;
                if (lineWidth2 == 0)
                {
                    widthAddon = 1;
                }

                if (((orientation & BarcodeLib.Scanner.MWB_SCANDIRECTION_HORIZONTAL) > 0) || ((orientation & BarcodeLib.Scanner.MWB_SCANDIRECTION_OMNI) > 0))
                {
                    bitmapLine.FillRectangle(rectLeft, rectTop + rectHeight / 2 - lineWidth2, rectRight, rectTop + rectHeight / 2 + lineWidth2 + widthAddon, colorFromAlphaAndInt(blinkingLineAlpha, blinkingLineColor));
                }

                if (((orientation & BarcodeLib.Scanner.MWB_SCANDIRECTION_VERTICAL) > 0) || ((orientation & BarcodeLib.Scanner.MWB_SCANDIRECTION_OMNI) > 0))
                {
                    bitmapLine.FillRectangle(rectLeft + rectWidth / 2 - lineWidth2, rectTop, rectLeft + rectWidth / 2 + lineWidth2 + widthAddon, rectBottom, colorFromAlphaAndInt(blinkingLineAlpha, blinkingLineColor));
                }

                if ((orientation & BarcodeLib.Scanner.MWB_SCANDIRECTION_OMNI) > 0)
                {
                    bitmapLine.DrawLine(rectLeft, rectTop, rectRight, rectBottom, colorFromAlphaAndInt(blinkingLineAlpha, blinkingLineColor));
                    bitmapLine.DrawLine(rectLeft, rectBottom, rectRight, rectTop, colorFromAlphaAndInt(blinkingLineAlpha, blinkingLineColor));
                }

                lineLayer.Source = bitmapLine;
            }
            else
            {
                lineLayer.Visibility = Visibility.Collapsed;
                removeAnimation();
            }
        }