Beispiel #1
0
        public static void SetHideFormAccessoryBar(bool hide)
        {
            if (hide == _hideFormAccessoryBar)
            {
                return;
            }
            var uiMethod = class_getInstanceMethod(Class.GetHandle("UIWebBrowserView"), new Selector("inputAccessoryView").Handle);
            var wkMethod = class_getInstanceMethod(Class.GetHandle("WKContentView"), new Selector("inputAccessoryView").Handle);

            if (hide)
            {
                UIOriginalImp = method_getImplementation(uiMethod);
                WKOriginalImp = method_getImplementation(wkMethod);

                var             block_value = new BlockLiteral();
                CaptureDelegate d           = MyCapture;
                block_value.SetupBlock(d, null);
                var nilimp = imp_implementationWithBlock(ref block_value);
                method_setImplementation(uiMethod, nilimp);
                method_setImplementation(wkMethod, nilimp);
            }
            else
            {
                method_setImplementation(uiMethod, UIOriginalImp);
                method_setImplementation(wkMethod, WKOriginalImp);
            }
            _hideFormAccessoryBar = hide;
        }
        bool SetupCaptureSession()
        {
            session = new AVCaptureSession();

            AVCaptureDevice device = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);

            if (device == null)
            {
                Console.WriteLine("No video camera (in simulator?)");
                return(false);                // simulator?
            }

            NSError error = null;

            AVCaptureDeviceInput input = AVCaptureDeviceInput.FromDevice(device, out error);

            if (input == null)
            {
                Console.WriteLine("Error: " + error);
            }
            else
            {
                session.AddInput(input);
            }

            AVCaptureMetadataOutput output = new AVCaptureMetadataOutput();

            var dg = new CaptureDelegate(this);

            output.SetDelegate(dg, MonoTouch.CoreFoundation.DispatchQueue.MainQueue);
            session.AddOutput(output);

            // This could be any list of supported barcode types
            output.MetadataObjectTypes = new NSString[] { AVMetadataObject.TypeQRCode, AVMetadataObject.TypeAztecCode };
            // OR you could just accept "all" with the following line;
//			output.MetadataObjectTypes = output.AvailableMetadataObjectTypes;  // empty
            // DEBUG: use this if you're curious about the available types
//			foreach (var t in output.AvailableMetadataObjectTypes)
//				Console.WriteLine(t);


            AVCaptureVideoPreviewLayer previewLayer = new AVCaptureVideoPreviewLayer(session);

            //previewLayer.Frame = new RectangleF(0,0, View.Frame.Size.Width, View.Frame.Size.Height);
            previewLayer.Frame        = new RectangleF(0, 0, 320, 290);
            previewLayer.VideoGravity = AVLayerVideoGravity.ResizeAspectFill.ToString();
            View.Layer.AddSublayer(previewLayer);

            session.StartRunning();

            Console.WriteLine("StartRunning");
            return(true);
        }
Beispiel #3
0
        private static void Hijack(NSObject obj, string selector, ref IntPtr originalImpl, CaptureDelegate captureDelegate)
        {
            var method = class_getInstanceMethod(obj.ClassHandle, new Selector(selector).Handle);

            originalImpl = method_getImplementation(method);
            if (originalImpl != IntPtr.Zero)
            {
                var block_value = new BlockLiteral();
                block_value.SetupBlock(captureDelegate, null);
                var imp = imp_implementationWithBlock(ref block_value);
                method_setImplementation(method, imp);
            }
        }
        bool SetupCaptureSession()
        {
            session = new AVCaptureSession();

            AVCaptureDevice device = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);

            if (device == null) {
                Console.WriteLine("No video camera (in simulator?)");
                return false; // simulator?
            }

            NSError error = null;

            AVCaptureDeviceInput input = AVCaptureDeviceInput.FromDevice(device, out error);

            if (input == null)
                Console.WriteLine("Error: " + error);
            else
                session.AddInput(input);

            AVCaptureMetadataOutput output = new AVCaptureMetadataOutput();

            var dg = new CaptureDelegate(this);
            output.SetDelegate(dg,	MonoTouch.CoreFoundation.DispatchQueue.MainQueue);
            session.AddOutput(output);

            // This could be any list of supported barcode types
            output.MetadataObjectTypes = new NSString[] {AVMetadataObject.TypeQRCode, AVMetadataObject.TypeAztecCode};
            // OR you could just accept "all" with the following line;
            //			output.MetadataObjectTypes = output.AvailableMetadataObjectTypes;  // empty
            // DEBUG: use this if you're curious about the available types
            //			foreach (var t in output.AvailableMetadataObjectTypes)
            //				Console.WriteLine(t);

            AVCaptureVideoPreviewLayer previewLayer = new AVCaptureVideoPreviewLayer(session);
            //previewLayer.Frame = new RectangleF(0,0, View.Frame.Size.Width, View.Frame.Size.Height);
            previewLayer.Frame = new RectangleF(0, 0, 320, 290);
            previewLayer.VideoGravity = AVLayerVideoGravity.ResizeAspectFill.ToString();
            View.Layer.AddSublayer (previewLayer);

            session.StartRunning();

            Console.WriteLine("StartRunning");
            return true;
        }
Beispiel #5
0
 public void AddCaptureCallback(CaptureDelegate func)
 {
     captureDeletages.Add(func);
 }
Beispiel #6
0
 private static void Hijack(NSObject obj, string selector, ref IntPtr originalImpl, CaptureDelegate captureDelegate)
 {
     var method = class_getInstanceMethod (obj.ClassHandle, new Selector (selector).Handle);
       originalImpl = method_getImplementation (method);
       if(originalImpl != IntPtr.Zero) {
     var block_value = new BlockLiteral();
     block_value.SetupBlock(captureDelegate, null);
     var imp = imp_implementationWithBlock(ref block_value);
     method_setImplementation(method, imp);
       }
 }
Beispiel #7
0
        private void ImageCapTimer_Tick(object sender, EventArgs e)
        {
            CaptureDelegate captureDelegate = new CaptureDelegate(InternalCapture);

            captureDelegate.BeginInvoke(null, null);
        }