Exemplo n.º 1
0
        //this should ultimately be user driven like google photos can recycle code below later to find out hardware capabilites when giving users options
        private void SetVideoSize(CameraFacing camface) //determines cameras supported sizes and sets frame sizes for video as best as possible
        {
            CameraManager manager = (CameraManager)GetSystemService(Context.CameraService);
            var           cams    = manager.GetCameraIdList();

            LensFacing lensface = camface == CameraFacing.Back ? LensFacing.Back : LensFacing.Front;

            foreach (var camid in cams)
            {
                var camprops = manager.GetCameraCharacteristics(camid);

                if ((int)camprops.Get(CameraCharacteristics.LensFacing) == (int)lensface)
                {
                    var    map   = (StreamConfigurationMap)camprops.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
                    Size[] sizes = map.GetOutputSizes((int)ImageFormatType.Jpeg);
                    if (sizes.ToList().Any(s => s.Width == 1280 && s.Height == 720)) //if this format is supported then always use it, this is 16:9 aspect HD
                    {
                        pFramewidth  = 1280;
                        pFrameHeight = 720;
                    }
                    else //if (sizes.ToList().Any(s => s.Width == 640 && s.Height == 480)) //if HD is not supported use this default
                    {//if HD is not supported use this default
                        pFramewidth  = 640;
                        pFrameHeight = 480;
                    }
                }
            }
        }
Exemplo n.º 2
0
        void SwitchCameraButtonTapped(object sender, EventArgs e)
        {
            if (isLoading)
            {
                return;
            }

            if (cameraType == CameraFacing.Front)
            {
                cameraType = CameraFacing.Back;

                camera.StopPreview();
                camera.Release();
                camera = global::Android.Hardware.Camera.Open((int)cameraType);
                camera.SetPreviewTexture(surfaceTexture);
                PrepareAndStartCamera();
            }
            else
            {
                cameraType = CameraFacing.Front;

                camera.StopPreview();
                camera.Release();
                camera = global::Android.Hardware.Camera.Open((int)cameraType);
                camera.SetPreviewTexture(surfaceTexture);
                PrepareAndStartCamera();
            }
        }
Exemplo n.º 3
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            {
                return;
            }

            try {
                activity   = this.Context as Activity;
                view       = activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false);
                cameraType = CameraFacing.Back;

                textureView = view.FindViewById <TextureView> (Resource.Id.textureView);
                textureView.SurfaceTextureListener = this;

                takePhotoButton        = view.FindViewById <global::Android.Widget.Button> (Resource.Id.takePhotoButton);
                takePhotoButton.Click += TakePhotoButtonTapped;

                switchCameraButton        = view.FindViewById <global::Android.Widget.Button> (Resource.Id.switchCameraButton);
                switchCameraButton.Click += SwitchCameraButtonTapped;

                toggleFlashButton        = view.FindViewById <global::Android.Widget.Button> (Resource.Id.toggleFlashButton);
                toggleFlashButton.Click += ToggleFlashButtonTapped;

                AddView(view);
            } catch (Exception ex) {
                //Xamarin.Insights.Report (ex);
            }
        }
Exemplo n.º 4
0
        //switches between front and back cameras when button is clicked
        void SwitchCameraButtonTapped(object sender, EventArgs e)
        {
            //if camera isn't started
            if (!_isCameraStarted)
            {
                return;
            }

            if (cameraType == CameraFacing.Front)
            {
                cameraType = CameraFacing.Back;

                camera.StopPreview();
                camera.Release();
                camera = Android.Hardware.Camera.Open((int)cameraType);
                camera.SetPreviewTexture(surfaceTexture);
                PrepareAndStartCamera();
            }
            else
            {
                cameraType = CameraFacing.Front;

                camera.StopPreview();
                camera.Release();
                camera = Android.Hardware.Camera.Open((int)cameraType);
                camera.SetPreviewTexture(surfaceTexture);
                PrepareAndStartCamera();
            }
        }
Exemplo n.º 5
0
        /**
         * Creates and starts the camera.  Note that this uses a higher resolution in comparison
         * to other detection examples to enable the barcode detector to detect small barcodes
         * at long distances.
         */
        private void CreateCameraSource(CameraFacing direction)
        {
            var          context  = Application.Context;
            FaceDetector detector = new FaceDetector.Builder(context)
                                    .SetClassificationType(ClassificationType.All)
                                    .Build();

            detector.SetProcessor(
                new MultiProcessor.Builder(this)
                .Build());

            if (!detector.IsOperational)
            {
                // Note: The first time that an app using face API is installed on a device, GMS will
                // download a native library to the device in order to do detection.  Usually this
                // completes before the app is run for the first time.  But if that download has not yet
                // completed, then the above call will not detect any faces.
                //
                // isOperational() can be used to check if the required native library is currently
                // available.  The detector will automatically become operational once the library
                // download completes on device.
                Log.Warn(TAG, "Face detector dependencies are not yet available.");
            }

            _mCameraSource = new CameraSource.Builder(context, detector)
                             .SetRequestedPreviewSize(640, 480)
                             .SetFacing(direction)
                             .SetRequestedFps(30.0f)
                             .Build();
        }
Exemplo n.º 6
0
        //public void RefreshCamera()
        //{
        //    if (_holder == null) return;

        //    ApplyCameraSettings();

        //    try
        //    {
        //        Camera.SetPreviewDisplay(_holder);
        //        Camera.StartPreview();
        //    }
        //    catch (Exception ex)
        //    {
        //        Android.Util.Log.Debug(nameof(CameraController), ex.ToString());
        //    }
        //}



        public void SetupCamera(CameraFacing facing)
        {
            if (Camera != null)
            {
                return;
            }

            PermissionsHandler.CheckCameraPermissions(_context);


            OpenCamera(facing);


            if (Camera == null)
            {
                return;
            }


            ApplyCameraSettings();

            try
            {
                Camera.SetPreviewDisplay(_holder);


                //var previewParameters = Camera.GetParameters();
                //var previewSize = previewParameters.PreviewSize;
                //var bitsPerPixel = ImageFormat.GetBitsPerPixel(previewParameters.PreviewFormat);


                //int bufferSize = (previewSize.Width * previewSize.Height * bitsPerPixel) / 8;
                //const int NUM_PREVIEW_BUFFERS = 5;
                //for (uint i = 0; i < NUM_PREVIEW_BUFFERS; ++i)
                //{
                //    using (var buffer = new FastJavaByteArray(bufferSize))
                //        Camera.AddCallbackBuffer(buffer);
                //}



                Camera.StartPreview();

                // Camera.SetNonMarshalingPreviewCallback(_cameraEventListener);
            }
            catch (Exception ex)
            {
                Android.Util.Log.Debug(nameof(CameraController), ex.ToString());
                return;
            }

            // Docs suggest if Auto or Macro modes, we should invoke AutoFocus at least once
            var currentFocusMode = Camera.GetParameters().FocusMode;

            if (currentFocusMode == Camera.Parameters.FocusModeAuto ||
                currentFocusMode == Camera.Parameters.FocusModeMacro)
            {
                AutoFocus();
            }
        }
Exemplo n.º 7
0
        void ToggleFlashButtonTapped(object sender, EventArgs e)
        {
            flashOn = !flashOn;
            if (flashOn)
            {
                if (cameraType == CameraFacing.Back)
                {
                    toggleFlashButton.SetBackgroundResource(Resource.Drawable.FlashButton);
                    cameraType = CameraFacing.Back;

                    camera.StopPreview();
                    camera.Release();
                    camera = global::Android.Hardware.Camera.Open((int)cameraType);
                    var parameters = camera.GetParameters();
                    parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeTorch;
                    camera.SetParameters(parameters);
                    camera.SetPreviewTexture(surfaceTexture);
                    PrepareAndStartCamera();
                }
            }
            else
            {
                toggleFlashButton.SetBackgroundResource(Resource.Drawable.NoFlashButton);
                camera.StopPreview();
                camera.Release();

                camera = global::Android.Hardware.Camera.Open((int)cameraType);
                var parameters = camera.GetParameters();
                parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeOff;
                camera.SetParameters(parameters);
                camera.SetPreviewTexture(surfaceTexture);
                PrepareAndStartCamera();
            }
        }
Exemplo n.º 8
0
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        var data = new CameraFacing {
        };

        dstManager.AddComponentData(entity, data);
    }
Exemplo n.º 9
0
		protected override void OnElementChanged (ElementChangedEventArgs<Page> e)
		{
			base.OnElementChanged (e);

			if (e.OldElement != null || Element == null)
				return;

			try {
				activity = this.Context as Activity;
				view = activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false);
				cameraType = CameraFacing.Back;

				textureView = view.FindViewById<TextureView> (Resource.Id.textureView);
				textureView.SurfaceTextureListener = this;

				takePhotoButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.takePhotoButton);
				takePhotoButton.Click += TakePhotoButtonTapped;

				switchCameraButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.switchCameraButton);
				switchCameraButton.Click += SwitchCameraButtonTapped;

				toggleFlashButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.toggleFlashButton);
				toggleFlashButton.Click += ToggleFlashButtonTapped;

				AddView (view);
			} catch (Exception ex) {
				//Xamarin.Insights.Report (ex);
			}
		}
Exemplo n.º 10
0
 /// <summary>
 ///  Sets the camera attributes for size and facing direction, which informs how to transform image coordinates later.
 /// </summary>
 /// <param name="previewWidth"></param>
 /// <param name="previewHeight"></param>
 /// <param name="facing"></param>
 public void SetCameraInfo(int previewWidth, int previewHeight, CameraFacing facing)
 {
     lock (mLock) {
         PreviewWidth  = previewWidth;
         PreviewHeight = previewHeight;
         CameraFacing  = facing;
     }
     PostInvalidate();
 }
		void SetupUserInterface ()
		{
			activity = this.Context as Activity;
			view = activity.LayoutInflater.Inflate (Resource.Layout.CameraLayout, this, false);
			cameraType = CameraFacing.Back;

			textureView = view.FindViewById<TextureView> (Resource.Id.textureView);
			textureView.SurfaceTextureListener = this;
		}
Exemplo n.º 12
0
        private void SetDiyParams(Context context, IAttributeSet attrs)
        {
            var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.YsCameraX);

            CaptureImageSize_Width  = a.GetInt(Resource.Styleable.YsCameraX_CapturePictureSize_Width, 1280);
            CaptureImageSize_Height = a.GetInt(Resource.Styleable.YsCameraX_CapturePictureSize_Height, 720);
            CameraFacing            = (CameraFacing)a.GetInt(Resource.Styleable.YsCameraX_Camera_Facing, 0);
            a.Recycle();
        }
Exemplo n.º 13
0
        private int SwitchCamera()
        {
            int cameraId = 1;//NextCameraId();

            _camera = Camera.Open(cameraId);
            _currentCameraFacing = _cameraInfo.GetCameraFacing(cameraId);

            return(cameraId);
        }
Exemplo n.º 14
0
        void SetupUserInterface()
        {
            activity   = this.Context as Activity;
            view       = activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false);
            cameraType = CameraFacing.Back;

            textureView = view.FindViewById <TextureView>(Resource.Id.textureView);
            textureView.SurfaceTextureListener = this;
        }
Exemplo n.º 15
0
 /**
  * Sets the height and width of the camera
  */
 public void SetInformationFromCamera(int previewWidth, int previewHeight, CameraFacing cameraFacing)
 {
     lock (isBlocked)
     {
         pixelsX           = previewWidth;
         pixelsY           = previewHeight;
         this.cameraFacing = cameraFacing;
     }
     PostInvalidate();
 }
Exemplo n.º 16
0
        private void SetupUserInterface()
        {
            _activity   = Context as Activity;
            _view       = _activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false);
            _cameraType = CameraFacing.Back;

            _textureView = _view.FindViewById <TextureView>(Resource.Id.textureView);
            _textureView.SurfaceTextureListener = this;
            _textureView.SetOnTouchListener(this);
        }
Exemplo n.º 17
0
 public void SetCameraInfo(int previewWidth, int previewHeight, CameraFacing facing)
 {
     lock (_lockObj)
     {
         _previewWidth  = previewWidth;
         _previewHeight = previewHeight;
         _facing        = facing;
     }
     base.PostInvalidate();
 }
Exemplo n.º 18
0
 private void SwitchCameraButtonTapped(object sender, EventArgs e)
 {
     cameraType = cameraType == CameraFacing.Front ?
                  CameraFacing.Back : CameraFacing.Front;
     camera.StopPreview();
     camera.Release();
     camera = global::Android.Hardware.Camera.Open((int)cameraType);
     camera.SetPreviewTexture(surfaceTexture);
     PrepareAndStartCamera();
 }
Exemplo n.º 19
0
        private int SwitchCamera()
        {
            try
            {
                int cameraId = int.Parse(MainValues.front_back);//NextCameraId();
                _camera = Camera.Open(cameraId);
                _currentCameraFacing = _cameraInfo.GetCameraFacing(cameraId);

                return(cameraId);
            }
            catch (Exception) { return(5); }
        }
Exemplo n.º 20
0
        public CameraPage()
        {
            activity = this.Context as MainActivity;

            view       = activity.LayoutInflater.Inflate(Resource.Layout.CameraLayoutOld, this, false);
            cameraType = CameraFacing.Back;

            textureView = view.FindViewById <TextureView>(Resource.Id.textureView);
            textureView.SurfaceTextureListener = this;

            previousPhoto = view.FindViewById <ImageView>(Resource.Id.previousPhoto);
        }
Exemplo n.º 21
0
    void Awake()
    {
        meshFilter   = GetComponent <MeshFilter>();
        cameraFacing = GetComponent <CameraFacing>();

        vertices  = new List <Vector3>();
        colors    = new List <Color>();
        uvs       = new List <Vector2>();
        triangles = new List <int>();

        mesh = meshFilter.mesh;
    }
Exemplo n.º 22
0
    void Awake()
    {
        meshFilter = GetComponent<MeshFilter>();
        cameraFacing = GetComponent<CameraFacing>();

        vertices = new List<Vector3>();
        colors = new List<Color>();
        uvs = new List<Vector2>();
        triangles = new List<int>();

        mesh = meshFilter.mesh;
    }
Exemplo n.º 23
0
        private void SwitchCameraButton_Click(object sender, EventArgs e)
        {
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                string[] camPermissions = { Android.Manifest.Permission.Camera };

                // Make sure we can use the camera
                if ((int)Android.OS.Build.VERSION.SdkInt >= 23 && Activity.CheckSelfPermission(camPermissions[0]) != (Permission.Granted))
                {
                    Toast.MakeText(Activity, AppResources.Camera_permissionNeeded, ToastLength.Long).Show();
                    Activity.RequestPermissions(camPermissions, CamPermReqId);
                    return;
                }

                mCameraDevice.Close();

                int newCamIndex = backCam ? 1 : 0;
                backCam = !backCam;

                try
                {
                    OpenCamera(newCamIndex);
                }
                catch (System.Exception ex)
                {
                    System.Console.WriteLine(ex);
                }
            }
            else
            {
                if (cameraType == CameraFacing.Front)
                {
                    cameraType = CameraFacing.Back;

                    camera.StopPreview();
                    camera.Release();
                    camera = Android.Hardware.Camera.Open((int)cameraType);
                    camera.SetPreviewTexture(surfaceTexture);
                    PrepareAndStartCamera1();
                }
                else
                {
                    cameraType = CameraFacing.Front;

                    camera.StopPreview();
                    camera.Release();
                    camera = Android.Hardware.Camera.Open((int)cameraType);
                    camera.SetPreviewTexture(surfaceTexture);
                    PrepareAndStartCamera1();
                }
            }
        }
Exemplo n.º 24
0
 private void ToggleCamface()
 {
     if (camface == CameraFacing.Front)
     {
         camface = CameraFacing.Back;
         ReleaseRestartResources(false);
     }
     else
     {
         camface = CameraFacing.Front;
         ReleaseRestartResources(false);
     }
 }
Exemplo n.º 25
0
        void ToggleFlashButtonTapped(object sender, EventArgs e)
        {
            flashOn = !flashOn;
            if (flashOn)
            {
                if (cameraType == CameraFacing.Back)
                {
                    toggleFlashButton.SetBackgroundResource(Resource.Drawable.FlashButton);
                    cameraType = CameraFacing.Back;

                    camera.StopPreview();
                    camera.Release();
                    camera = global::Android.Hardware.Camera.Open((int)cameraType);
                    var parameters = camera.GetParameters();
                    parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeTorch;
                    camera.SetParameters(parameters);
                    camera.SetPreviewTexture(surfaceTexture);

                    PrepareAndStartCamera();
                }
            }
            else
            {
                toggleFlashButton.SetBackgroundResource(Resource.Drawable.NoFlashButton);
                camera.StopPreview();
                camera.Release();

                camera = global::Android.Hardware.Camera.Open((int)cameraType);


                var infoFocusCalibration      = global::Android.Hardware.Camera2.CameraCharacteristics.LensInfoFocusDistanceCalibration;
                var infoSupportHardLevel      = global::Android.Hardware.Camera2.CameraCharacteristics.InfoSupportedHardwareLevel;
                var infoMinimumFocus          = global::Android.Hardware.Camera2.CameraCharacteristics.LensPoseRotation;
                var infoSensorActiveArraySize = global::Android.Hardware.Camera2.CameraCharacteristics.SensorInfoActiveArraySize;

                //var paramters2 = camera2.

                var parameters = camera.GetParameters();

                parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeOff;
                parameters.FocusMode = global::Android.Hardware.Camera.Parameters.FocusModeAuto;

                camera.SetParameters(parameters);
                camera.SetPreviewTexture(surfaceTexture);
                camera.SetDisplayOrientation(100);
                var max = camera.GetParameters().MaxNumFocusAreas;

                PrepareAndStartCamera();
                camera.StartFaceDetection();
            }
        }
        private void SetupUserInterface()
        {
            activity   = Context as Activity;
            view       = activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false);
            cameraType = CameraFacing.Back;

            textureView = view.FindViewById <TextureView>(Resource.Id.textureView);
            textureView.SurfaceTextureListener = this;

            takePhotoButton    = view.FindViewById <Button>(Resource.Id.takePhotoButton);
            switchCameraButton = view.FindViewById <Button>(Resource.Id.switchCameraButton);
            toggleFlashButton  = view.FindViewById <Button>(Resource.Id.toggleFlashButton);
            cancelButton       = view.FindViewById <Button>(Resource.Id.cancelButton);
        }
Exemplo n.º 27
0
        private void OpenCamera(CameraFacing whichCamera)
        {
            try
            {
                var version = Build.VERSION.SdkInt;

                if (version >= BuildVersionCodes.Gingerbread)
                {
                    var numCameras = Camera.NumberOfCameras;
                    var camInfo    = new Camera.CameraInfo();
                    var found      = false;



                    for (var i = 0; i < numCameras; i++)
                    {
                        Camera.GetCameraInfo(i, camInfo);
                        if (camInfo.Facing == whichCamera)
                        {
                            Camera    = Camera.Open(i);
                            _cameraId = i;
                            found     = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        Camera    = Camera.Open(0);
                        _cameraId = 0;
                    }
                }
                else
                {
                    Camera = Camera.Open();
                }

                //if (Camera != null)
                //    Camera.SetPreviewCallback(_cameraEventListener);
                //else
                //    MobileBarcodeScanner.LogWarn(MobileBarcodeScanner.TAG, "Camera is null :(");
            }
            catch (Exception ex)
            {
                ShutdownCamera();
                // MobileBarcodeScanner.LogError("Setup Error: {0}", ex);
            }
        }
Exemplo n.º 28
0
    private void ActivateCamera(CameraFacing facing)
    {
        if (!initialized)
        {
            return;
        }

        // Any spray compositing that happens while the camera is initializing should spray pitch black.
        activeTexture       = Texture2D.blackTexture;
        staleFramesReceived = 0;

        var device = (facing == CameraFacing.Front) ? DeviceCamera.FrontCamera : DeviceCamera.RearCamera;

        if (device != null)
        {
            // We can't change the resolution while the preview is playing.
            if (NatCam.IsPlaying)
            {
                NatCam.Pause();
            }

            NatCam.ActiveCamera     = device;
            NatCam.OnPreviewStart  += OnPreviewStart;
            NatCam.OnPreviewUpdate += OnPreviewUpdate;

            NatCam.ActiveCamera.SetFramerate(deviceCameraFramerate);
            NatCam.ActiveCamera.SetResolution(deviceCameraResolution);

            // The exposure and focus modes are only available on the native interface.
            if (NatCam.Interface == NatCamInterface.NativeInterface)
            {
                NatCam.ActiveCamera.FocusMode    = deviceCameraFocusMode;
                NatCam.ActiveCamera.ExposureMode = deviceCameraExposureMode;
            }

            NatCam.Play();

            if (FacingChanged != null)
            {
                FacingChanged(facing);
            }
        }
        else if (Debug.isDebugBuild)
        {
            Debug.LogError("CameraCapture: no camera for this orientation");
        }
    }
Exemplo n.º 29
0
        public void CreateCameraSource(CameraFacing cameraFacing)
        {
            FaceDetector detector = new FaceDetector.Builder(this).Build();

            detector.SetProcessor(new MultiProcessor.Builder(this).Build());

            if (!detector.IsOperational)
            {
                Log.Warn(TAG, "Face detector isn't configured yet");
            }

            cameraSource = new CameraSource.Builder(this, detector)
                           .SetRequestedPreviewSize(640, 480)
                           .SetFacing(cameraFacing)
                           .SetAutoFocusEnabled(true)
                           .SetRequestedFps(30.0f)
                           .Build();
        }
Exemplo n.º 30
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            var b = savedInstanceState ?? Intent.Extras;

            id    = b.GetInt(ExtraId);
            front = b.GetInt(ExtraFront);

            SetContentView(Resource.Layout.CameraLayout);

            cameraType = (CameraFacing)front;

            takePhotoButton        = FindViewById <Button>(Resource.Id.takePhotoButton);
            takePhotoButton.Click += TakePhotoButtonTapped;

            textureView = FindViewById <TextureView>(Resource.Id.textureView);
            textureView.SurfaceTextureListener = this;
        }
        private void BtnSwitchCamera_Click(object sender, EventArgs e)
        {
            switch (_cameraFacing)
            {
            case CameraFacing.Back:
                _cameraFacing = CameraFacing.Front;
                break;

            case CameraFacing.Front:
                _cameraFacing = CameraFacing.Back;
                break;

            default:
                return;
            }

            ReleaseCamera();
            InitializeCamera();
        }
        public void SetupUserInterface(int height, int width)
        {
            _activity = this.Context as Activity;
            if ((_view = _activity?.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false)) == null)
            {
                return;
            }
            var cameraView = _view.FindViewById <FrameLayout>(Resource.Id.cameraView);
            var parameters = cameraView.LayoutParameters;

            parameters.Height = height;
            parameters.Height = width;
            _cameraType       = CameraFacing.Front;

            this.AddView(_view);

            _textureView = _view.FindViewById <TextureView>(Resource.Id.textureView);
            _textureView.SurfaceTextureListener = this;
        }
Exemplo n.º 33
0
        void SetupUserInterface()
        {
            activity   = this.Context as Activity;
            view       = activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false);
            cameraType = CameraFacing.Back;

            textureView = view.FindViewById <TextureView>(Resource.Id.textureView);
            textureView.SurfaceTextureListener = this;

            OCR_textView     = view.FindViewById <TextView>(Resource.Id.myOCR_TextView);
            OCR_Rectangle    = view.FindViewById <ImageView>(Resource.Id.btn_capture_photo);
            OCR_Top_Left     = view.FindViewById <ImageView>(Resource.Id.Top_Left_photo);
            OCR_Top_Right    = view.FindViewById <ImageView>(Resource.Id.Top_Right_photo);
            OCR_Bottom_Left  = view.FindViewById <ImageView>(Resource.Id.Bottom_Left_photo);
            OCR_Bottom_Right = view.FindViewById <ImageView>(Resource.Id.Bottom_Right_photo);

            Canvas canvas = textureView.LockCanvas();
            Paint  paint;

            paint       = new Paint();
            paint.Color = Android.Graphics.Color.Red;
            paint.SetStyle(Paint.Style.Stroke);
            paint.StrokeWidth = 2f;
            Rect r = new Rect((int)100, (int)100, (int)200, (int)200);
            // canvas.DrawRect(r, paint);



            var absolutePath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim).AbsolutePath;

            if (!Directory.Exists(absolutePath + "/tessdata"))
            {
                Directory.CreateDirectory(absolutePath + "/tessdata");
            }
            if (!File.Exists(absolutePath + "/tessdata/eng.traineddata"))
            {
                string destPath = absolutePath + "/tessdata/eng.traineddata";
                using (var source = activity.Assets.Open("eng.traineddata"))
                    using (var dest = File.OpenWrite(destPath))
                        source.CopyTo(dest);
            }
        }
Exemplo n.º 34
0
		protected override void OnCreate(Bundle bundle)
		{
			base.OnCreate(bundle);

			if (this.Intent != null)
			{
				var receiverID = this.Intent.GetStringExtra(KEY_RECEIVER_ID);
				if(receiverID != null)
					_receiverID = new Guid(receiverID);
			}

			this.SetContentView(Resource.Layout.activity_camera);

			try
			{
				
				cameraType = CameraFacing.Back;

				textureView = this.FindViewById<TextureView>(Resource.Id.textureView);
				textureView.SurfaceTextureListener = this;

				takePhotoButton = this.FindViewById<global::Android.Widget.Button>(Resource.Id.takePhotoButton);
				takePhotoButton.Click += TakePhotoButtonTapped;

				switchCameraButton = this.FindViewById<global::Android.Widget.Button>(Resource.Id.switchCameraButton);
				switchCameraButton.Click += SwitchCameraButtonTapped;

				toggleFlashButton = this.FindViewById<global::Android.Widget.Button>(Resource.Id.toggleFlashButton);
				toggleFlashButton.Click += ToggleFlashButtonTapped;

			}
			catch (Exception ex)
			{
				Xamarin.Insights.Report(ex);
			}
		}
Exemplo n.º 35
0
        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
                return;

            try
            {
                var activity = this.Context as Activity;
                activity.RequestedOrientation = ScreenOrientation.Landscape;
                view = activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false);
                _textureView = view.FindViewById<TextureView>(Resource.Id.textureView);
                _textureView.SurfaceTextureListener = this;
                cameraType = CameraFacing.Back;
                AddView(view);
            }
            catch (Exception ex)
            {

                Console.WriteLine("Roland error...." + ex.Message);
            }
        }
Exemplo n.º 36
0
		private void ToggleFlashButtonTapped(object sender, EventArgs e)
		{
			_flashOn = !_flashOn;
			if (_flashOn)
			{
				if (cameraType == CameraFacing.Back)
				{
					toggleFlashButton.SetBackgroundResource(Resource.Drawable.FlashButton);
					cameraType = CameraFacing.Back;

					camera.StopPreview();
					camera.Release();
					camera = global::Android.Hardware.Camera.Open((int)cameraType);
					var parameters = camera.GetParameters();
					parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeTorch;
					camera.SetParameters(parameters);
					camera.SetPreviewTexture(surfaceTexture);
					PrepareAndStartCamera();
				}
			}
			else
			{
				toggleFlashButton.SetBackgroundResource(Resource.Drawable.NoFlashButton);
				camera.StopPreview();
				camera.Release();

				camera = global::Android.Hardware.Camera.Open((int)cameraType);
				var parameters = camera.GetParameters();
				parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeOff;
				camera.SetParameters(parameters);
				camera.SetPreviewTexture(surfaceTexture);
				PrepareAndStartCamera();
			}
		}
Exemplo n.º 37
0
		private void SwitchCameraButtonTapped(object sender, EventArgs e)
		{
			if (cameraType == CameraFacing.Front)
			{
				cameraType = CameraFacing.Back;

				camera.StopPreview();
				camera.Release();
				camera = global::Android.Hardware.Camera.Open((int)cameraType);
				camera.SetPreviewTexture(surfaceTexture);
				PrepareAndStartCamera();
			}
			else
			{
				cameraType = CameraFacing.Front;

				camera.StopPreview();
				camera.Release();
				camera = global::Android.Hardware.Camera.Open((int)cameraType);
				camera.SetPreviewTexture(surfaceTexture);
				PrepareAndStartCamera();
			}
		}