Пример #1
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            //Create a new instance of our scanner
            scanner = new ZxingScanner();
        }
Пример #2
0
 public ZxingCameraViewController(ZxingScanningOptions options, ZxingScanner scanner)
     : base()
 {
     this.ScanningOptions = options;
     this.Scanner         = scanner;
     Initialize();
 }
        public ZxingCameraViewController(ZxingScanningOptions options, ZxingScanner scanner)
            : base()
        {
			this.ScanningOptions = options;
			this.Scanner = scanner;
            Initialize();
        }
		public override void ViewDidLoad ()
		{
			//Create a new instance of our scanner
			scanner = new ZxingScanner();

			//Setup our button
			buttonDefaultScan = new UIButton(UIButtonType.RoundedRect);
			buttonDefaultScan.Frame = new RectangleF(20, 80, 280, 40);
			buttonDefaultScan.SetTitle("Scan with Default View", UIControlState.Normal);
			buttonDefaultScan.TouchUpInside += (sender, e) => 
			{
				//Tell our scanner to use the default overlay
				scanner.UseCustomOverlay = false;
				//We can customize the top and bottom text of the default overlay
				scanner.TopText = "Hold camera up to barcode to scan";
				scanner.BottomText = "Barcode will automatically scan";

				//Start scanning
				scanner.StartScanning((result) => 
				{
					//Our scanning finished callback
					HandleScanResult(result);
				});
			};

			buttonCustomScan = new UIButton(UIButtonType.RoundedRect);
			buttonCustomScan.Frame = new RectangleF(20, 20, 280, 40);
			buttonCustomScan.SetTitle("Scan with Custom View", UIControlState.Normal);
			buttonCustomScan.TouchUpInside += (sender, e) =>
			{
				//Create an instance of our custom overlay
				customOverlay = new CustomOverlayView();
				//Wireup the buttons from our custom overlay
				customOverlay.ButtonTorch.TouchUpInside += delegate {
					scanner.ToggleTorch();		
				};
				customOverlay.ButtonCancel.TouchUpInside += delegate {
					scanner.StopScanning();
				};

				//Tell our scanner to use our custom overlay
				scanner.UseCustomOverlay = true;
				scanner.CustomOverlay = customOverlay;

				scanner.StartScanning((result) => 
				{
					//Our scanning finished callback
					HandleScanResult(result);
				});
			};

			this.View.AddSubview(buttonDefaultScan);
			this.View.AddSubview(buttonCustomScan);
		}
Пример #5
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);

			//Create a new instance of our Scanner
			scanner = new ZxingScanner(this);

			buttonScanDefaultView = this.FindViewById<Button>(Resource.Id.buttonScanDefaultView);
			buttonScanDefaultView.Click += delegate {
				
				//Tell our scanner to use the default overlay
				scanner.UseCustomOverlay = false;
				//We can customize the top and bottom text of the default overlay
				scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away";
				scanner.BottomText = "Wait for the barcode to automatically scan!";

				//Start scanning
				scanner.StartScanning((barcode) => {
					//Scanning finished callback
					HandleScanResult(barcode);
				});
			};

			buttonScanCustomView = this.FindViewById<Button>(Resource.Id.buttonScanCustomView);
			buttonScanCustomView.Click += delegate {

				//Tell our scanner we want to use a custom overlay instead of the default
				scanner.UseCustomOverlay = true;

				//Inflate our custom overlay from a resource layout
				var zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlay, null);

				//Find the button from our resource layout and wire up the click event
				var flashButton = zxingOverlay.FindViewById<Button>(Resource.Id.buttonZxingFlash);
				flashButton.Click += (sender, e) => {
					//Tell our scanner to toggle the torch/flash
					scanner.ToggleTorch();
				};

				//Set our custom overlay
				scanner.CustomOverlay = zxingOverlay;

				//Start scanning!
				scanner.StartScanning((barcode) => {
					//Our scanning finished callback
					HandleScanResult(barcode);
				});

			};
		}
        public ZxingSurfaceView(ZxingCameraViewController parentController, ZxingScanner scanner, ZxingScanningOptions options, UIView overlayView) : base()
        {
			var screenFrame = UIScreen.MainScreen.Bounds;
			var scale = UIScreen.MainScreen.Scale;
			screenFrame = new RectangleF(screenFrame.X, screenFrame.Y, screenFrame.Width * scale, screenFrame.Height * scale);

			var picFrameWidth = Math.Round(screenFrame.Width * 0.90); //screenFrame.Width;
			var picFrameHeight = Math.Round(screenFrame.Height * 0.60);
			var picFrameX = (screenFrame.Width - picFrameWidth) / 2;
			var picFrameY = (screenFrame.Height - picFrameHeight) / 2;

			picFrame = new RectangleF((int)picFrameX, (int)picFrameY, (int)picFrameWidth, (int)picFrameHeight);

			//Console.WriteLine(picFrame.X + ", " + picFrame.Y + " -> " + picFrame.Width + " x " + picFrame.Height);
			this.OverlayView = overlayView;
			this.Scanner = scanner;
			this.Options = options;

            Initialize();
			_parentViewController = parentController;
        }
        bool SetupCaptureSession()
        {
            // configure the capture session for low resolution, change this if your code
            // can cope with more data or volume
            session = new AVCaptureSession()
            {
                SessionPreset = AVCaptureSession.PresetMedium
            };

            // create a device input and attach it to the session
            captureDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);
            var input = AVCaptureDeviceInput.FromDevice(captureDevice);

            if (input == null)
            {
                // No input device
                return(false);
            }
            session.AddInput(input);

            // create a VideoDataOutput and add it to the sesion
            var output = new AVCaptureVideoDataOutput()
            {
                VideoSettings = new AVVideoSettings(CVPixelFormatType.CV32BGRA)
            };


            // configure the output
            queue   = new DispatchQueue("myQueue");
            scanner = new ZxingScanner(this);
            output.SetSampleBufferDelegateAndQueue(scanner, queue);
            session.AddOutput(output);

            previewLayer              = new AVCaptureVideoPreviewLayer(session);
            previewLayer.Orientation  = AVCaptureVideoOrientation.Portrait;
            previewLayer.VideoGravity = "AVLayerVideoGravityResizeAspectFill";

            session.StartRunning();
            return(true);
        }
        public ZxingSurfaceView(ZxingCameraViewController parentController, ZxingScanner scanner, ZxingScanningOptions options, UIView overlayView) : base()
        {
            var screenFrame = UIScreen.MainScreen.Bounds;
            var scale       = UIScreen.MainScreen.Scale;

            screenFrame = new RectangleF(screenFrame.X, screenFrame.Y, screenFrame.Width * scale, screenFrame.Height * scale);

            var picFrameWidth  = Math.Round(screenFrame.Width * 0.90);            //screenFrame.Width;
            var picFrameHeight = Math.Round(screenFrame.Height * 0.60);
            var picFrameX      = (screenFrame.Width - picFrameWidth) / 2;
            var picFrameY      = (screenFrame.Height - picFrameHeight) / 2;

            picFrame = new RectangleF((int)picFrameX, (int)picFrameY, (int)picFrameWidth, (int)picFrameHeight);

            //Console.WriteLine(picFrame.X + ", " + picFrame.Y + " -> " + picFrame.Width + " x " + picFrame.Height);
            this.OverlayView = overlayView;
            this.Scanner     = scanner;
            this.Options     = options;

            Initialize();
            _parentViewController = parentController;
        }
		bool SetupCaptureSession ()
		{
			// configure the capture session for low resolution, change this if your code
			// can cope with more data or volume
			session = new AVCaptureSession () {
				SessionPreset = AVCaptureSession.PresetMedium
			};

			// create a device input and attach it to the session
			captureDevice = AVCaptureDevice.DefaultDeviceWithMediaType (AVMediaType.Video);
			var input = AVCaptureDeviceInput.FromDevice (captureDevice);
			if (input == null){
				// No input device
				return false;
			}
			session.AddInput (input);

			// create a VideoDataOutput and add it to the sesion
			var output = new AVCaptureVideoDataOutput () {
				VideoSettings = new AVVideoSettings (CVPixelFormatType.CV32BGRA)
			};


			// configure the output
			queue = new DispatchQueue ("myQueue");
			scanner = new ZxingScanner (this);
			output.SetSampleBufferDelegateAndQueue (scanner, queue);
			session.AddOutput (output);
		
			previewLayer = new AVCaptureVideoPreviewLayer (session);
			previewLayer.Orientation = AVCaptureVideoOrientation.Portrait;
			previewLayer.VideoGravity = "AVLayerVideoGravityResizeAspectFill";

			session.StartRunning ();
			return true;
		}