public override void OnConfigured(CameraCaptureSession session)
        {
            // The camera is already closed
            if (null == Owner.mCameraDevice)
            {
                return;
            }

            // When the session is ready, we start displaying the preview.
            Owner.mCaptureSession = session;
            try
            {
                // Auto focus should be continuous for camera preview.
                Owner.mPreviewRequestBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
                // Flash is automatically enabled when necessary.
                Owner.SetAutoFlash(Owner.mPreviewRequestBuilder);

                // Finally, we start displaying the camera preview.
                Owner.mPreviewRequest = Owner.mPreviewRequestBuilder.Build();
                Owner.mCaptureSession.SetRepeatingRequest(Owner.mPreviewRequest,
                        Owner.mCaptureCallback, Owner.mBackgroundHandler);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
		public override void OnConfigured (CameraCaptureSession session)
		{
			//Start Recording
			try {
				session.SetRepeatingRequest(fragment.builder.Build(),null,null);
				fragment.media_recorder.Start();
			} catch (CameraAccessException e) {
				e.PrintStackTrace ();
			}

		}
 public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
 {
     Process(result);
 }
Exemplo n.º 4
0
        private void TakePhoto()
        {
            if (_context == null || CameraDevice == null)
            {
                return;
            }

            var characteristics = _manager.GetCameraCharacteristics(CameraDevice.Id);

            Size[] jpegSizes = null;
            if (characteristics != null)
            {
                jpegSizes = ((StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap)).GetOutputSizes((int)ImageFormatType.Jpeg);
            }
            var width  = 480;
            var height = 640;

            if (jpegSizes != null && jpegSizes.Length > 0)
            {
                width  = jpegSizes[0].Width;
                height = jpegSizes[0].Height;
            }

            var reader         = ImageReader.NewInstance(width, height, ImageFormatType.Jpeg, 1);
            var outputSurfaces = new List <Surface>(2)
            {
                reader.Surface, new Surface(_viewSurface)
            };

            var captureBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);

            captureBuilder.AddTarget(reader.Surface);
            captureBuilder.Set(CaptureRequest.ControlMode, new Integer((int)ControlMode.Auto));

            var windowManager = _context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            var rotation      = windowManager.DefaultDisplay.Rotation;

            captureBuilder.Set(CaptureRequest.JpegOrientation, new Integer(Orientations.Get((int)rotation)));

            var readerListener = new ImageAvailableListener();

            readerListener.Photo += (sender, buffer) =>
            {
                Photo?.Invoke(this, ImageSource.FromStream(() => new MemoryStream(buffer)));
            };

            var thread = new HandlerThread("CameraPicture");

            thread.Start();
            var backgroundHandler = new Handler(thread.Looper);

            reader.SetOnImageAvailableListener(readerListener, backgroundHandler);

            var captureListener = new CameraCaptureListener();

            captureListener.PhotoComplete += (sender, e) =>
            {
                StartPreview();
            };

            CameraDevice.CreateCaptureSession(outputSurfaces, new CameraCaptureStateListener
            {
                OnConfiguredAction = session =>
                {
                    try
                    {
                        _previewSession = session;
                        session.Capture(captureBuilder.Build(), captureListener, backgroundHandler);
                    }
                    catch (CameraAccessException ex)
                    {
                        Log.WriteLine(LogPriority.Info, "Capture Session error: ", ex.ToString());
                    }
                }
            }, backgroundHandler);
        }
Exemplo n.º 5
0
 public override void OnConfigureFailed(CameraCaptureSession session)
 {
     _owner.OnError("Session Configuration failed");
 }
 public override void OnConfigureFailed(CameraCaptureSession session)
 {
     Owner.ShowToast("Failed");
 }
Exemplo n.º 7
0
 internal void CloseCamera()
 {
     try
     {
         if (_captureSession != null)
         {
             _captureSession.Close();
             _captureSession = null;
         }
         if (CameraDevice != null)
         {
             CameraDevice.Close();
             CameraDevice = null;
         }
         if (_imageReader != null)
         {
             _imageReader.Close();
             _imageReader = null;
         }
     }
     catch { }
 }
Exemplo n.º 8
0
        private void StartPreview()
        {
            if (mCameraDevice == null || !mTextureView.IsAvailable || mPreviewSize == null)
            {
                return;
            }
            try
            {
                SurfaceTexture texture = mTextureView.SurfaceTexture;
                System.Diagnostics.Debug.Assert( texture != null);

                texture.SetDefaultBufferSize(mPreviewSize.Width, mPreviewSize.Height);

                Surface surface = new Surface(texture);

                mPreviewBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);

                mPreviewBuilder.AddTarget(surface);

                mCameraDevice.CreateCaptureSession(
                    new List<Surface>() {surface},

                    new CameraCaptureStateListener()
                    {
                        OnConfigureFailedAction = (CameraCaptureSession session) =>
                        {
                            Activity activity = Activity;

                            if(activity != null)
                            {
                                Toast.MakeText(activity, "Failed", ToastLength.Short).Show();
                            }
                        },
                        OnConfiguredAction = (CameraCaptureSession session) =>
                        {
                            mPreviewSession = session;
                            UpdatePreview ();
                        }
                    },
                    null);
            }
            catch(CameraAccessException ex)
            {
                Log.WriteLine (LogPriority.Info, "CameraFragment", ex.StackTrace);
            }
        }
 public override void OnConfigureFailed(CameraCaptureSession session)
 {
     Log.Warn(TAG, "Failed to configure camera");
 }
Exemplo n.º 10
0
		private void CloseCamera()
		{
			if (!CameraStarted)
			{
				return;
			}

			if (mPreviewSession != null)
			{
				mPreviewSession.Close();
				mPreviewSession = null;
			}
			if (mCameraDevice != null)
			{
				mCameraDevice.Close();
				mCameraDevice = null;
			}

		}
Exemplo n.º 11
0
			public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
			{
				if (Fragment != null && File != null)
				{
					Activity activity = Fragment.Activity;
					if (activity != null)
					{
						Fragment.PictureTaken(File.AbsolutePath);
					}
				}
			}
Exemplo n.º 12
0
        public void TakePhoto()
        {
            if (_context != null && cameraDevice != null)
            {
                try
                {
                    Busy?.Invoke(this, true);

                    if (_mediaSoundLoaded)
                    {
                        _mediaSound.Play(MediaActionSoundType.ShutterClick);
                    }

                    // Pick the best JPEG size that can be captures with this CameraDevice
                    var characteristics           = _manager.GetCameraCharacteristics(cameraDevice.Id);
                    Android.Util.Size[] jpegSizes = null;
                    if (characteristics != null)
                    {
                        jpegSizes = ((StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap)).GetOutputSizes((int)ImageFormatType.Jpeg);
                    }
                    int width  = 640;
                    int height = 480;

                    if (jpegSizes != null && jpegSizes.Length > 0)
                    {
                        width  = jpegSizes[0].Width;
                        height = jpegSizes[0].Height;
                    }

                    // We use an ImageReader to get a JPEG from CameraDevice
                    // Here, we create a new ImageReader and prepare its Surface as an output from the camera
                    var reader         = ImageReader.NewInstance(width, height, ImageFormatType.Jpeg, 1);
                    var outputSurfaces = new List <Surface>(2);
                    outputSurfaces.Add(reader.Surface);
                    outputSurfaces.Add(new Surface(_viewSurface));

                    CaptureRequest.Builder captureBuilder = cameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
                    captureBuilder.AddTarget(reader.Surface);
                    captureBuilder.Set(CaptureRequest.ControlMode, new Integer((int)ControlMode.Auto));

                    // Orientation
                    var windowManager           = _context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
                    SurfaceOrientation rotation = windowManager.DefaultDisplay.Rotation;

                    captureBuilder.Set(CaptureRequest.JpegOrientation, new Integer(ORIENTATIONS.Get((int)rotation)));

                    // This listener is called when an image is ready in ImageReader
                    ImageAvailableListener readerListener = new ImageAvailableListener();

                    readerListener.Photo += (sender, e) =>
                    {
                        Photo?.Invoke(this, e);
                    };

                    // We create a Handler since we want to handle the resulting JPEG in a background thread
                    HandlerThread thread = new HandlerThread("CameraPicture");
                    thread.Start();
                    Handler backgroundHandler = new Handler(thread.Looper);
                    reader.SetOnImageAvailableListener(readerListener, backgroundHandler);

                    var captureListener = new CameraCaptureListener();

                    captureListener.PhotoComplete += (sender, e) =>
                    {
                        Busy?.Invoke(this, false);
                        StartPreview();
                    };

                    cameraDevice.CreateCaptureSession(outputSurfaces, new CameraCaptureStateListener()
                    {
                        OnConfiguredAction = (CameraCaptureSession session) =>
                        {
                            try
                            {
                                _previewSession = session;
                                session.Capture(captureBuilder.Build(), captureListener, backgroundHandler);
                            }
                            catch (CameraAccessException ex)
                            {
                                Log.WriteLine(LogPriority.Info, "Capture Session error: ", ex.ToString());
                            }
                        }
                    }, backgroundHandler);
                }
                catch (CameraAccessException error)
                {
                    System.Diagnostics.Debug.WriteLine($"{error.Message} {error.StackTrace}");
                    //                    _log.WriteLineTime(_tag + "\n" +
                    //                        "TakePhoto() Failed to take photo  \n " +
                    //                        "ErrorMessage: \n" +
                    //                        error.Message + "\n" +
                    //                        "Stacktrace: \n " +
                    //                        error.StackTrace);
                }
                catch (Java.Lang.Exception error)
                {
                    System.Diagnostics.Debug.WriteLine($"{error.Message} {error.StackTrace}");
//                    _log.WriteLineTime(_tag + "\n" +
//                        "TakePhoto() Failed to take photo  \n " +
//                        "ErrorMessage: \n" +
//                        error.Message + "\n" +
//                        "Stacktrace: \n " +
//                        error.StackTrace);
                }
            }
        }
Exemplo n.º 13
0
 public override void OnConfigureFailed(CameraCaptureSession session)
 {
     Log.Debug(TAG, "CaptureSession OnConfiguredFailed error");
 }
Exemplo n.º 14
0
 public override void OnConfigureFailed(CameraCaptureSession session)
 {
     Log.Error(_tag, "Failed to configure camera.");
 }
Exemplo n.º 15
0
 public override void OnConfigured(CameraCaptureSession session)
 {
     owner.mCaptureSession = session;
     owner.UpdatePreview();
 }
Exemplo n.º 16
0
 public override void OnConfigured(CameraCaptureSession session)
 {
     _callback(session);
 }
Exemplo n.º 17
0
 public override void OnConfigureFailed(CameraCaptureSession session)
 {
     owner.ShowToast("Failed");
 }
Exemplo n.º 18
0
 public override void OnConfigured(CameraCaptureSession session)
 {
     session.SetRepeatingRequest(_captureRequest, new CameraCaptureSessionCallBack(), null);
     //session.StopRepeating();
     session.Capture(_captureRequest, new CameraCaptureSessionCallBack(), null);
 }
		public override void OnConfigured (CameraCaptureSession session)
		{
			fragment.previewSession = session;
			fragment.updatePreview ();

		}
Exemplo n.º 20
0
 public override void OnCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp, long frameNumber)
 {
     base.OnCaptureStarted(session, request, timestamp, frameNumber);
 }
			public override void OnConfigured (CameraCaptureSession session)
			{
				if (OnConfiguredAction != null) {
					OnConfiguredAction (session);
				}
			}
Exemplo n.º 22
0
 public override void OnCaptureProgressed(CameraCaptureSession session, CaptureRequest request,
                                          CaptureResult partialResult)
 {
     CaptureResultAvailable?.Invoke(this, partialResult);
 }
 public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
 {
     Process(result);
 }
Exemplo n.º 24
0
 public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
                                         TotalCaptureResult result)
 {
     CaptureResultAvailable?.Invoke(this, result);
 }
Exemplo n.º 25
0
 public override void OnConfigured(CameraCaptureSession session)
 {
     _owner.OnSessionConfigured(session);
 }
Exemplo n.º 26
0
 public override void OnConfigured(CameraCaptureSession session)
 {// sessionが生成されたとき
     owner.mCaptureSession = session;
     owner.mCaptureRequest = owner.mCaptureRequestBuilder.Build();
     session.SetRepeatingRequest(owner.mCaptureRequest, owner.mCameraCaptureSessionCaptureCallback, null);
 }
 public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
 {
     PhotoComplete?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 28
0
 public override void OnConfigureFailed(CameraCaptureSession session)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 29
0
 public void Work <TState>(CameraCaptureSession session, CaptureRequest request, CaptureResult result,
                           ref TState captureState) where TState : class
 {
 }
Exemplo n.º 30
0
 public override void OnConfigured(CameraCaptureSession session)
 {
     fragment.preview_session = session;
     fragment.updatePreview();
 }
 public override void OnCaptureProgressed(CameraCaptureSession session, CaptureRequest request, CaptureResult partialResult)
 {
     Process(partialResult);
 }
Exemplo n.º 32
0
        public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
        {
            MediaActionSound shutterSound = new MediaActionSound();

            shutterSound.Play(MediaActionSoundType.ShutterClick);
        }
Exemplo n.º 33
0
 public override void OnConfigureFailed(CameraCaptureSession session) { }
Exemplo n.º 34
0
 public override void OnConfigureFailed(CameraCaptureSession session)
 {
     Toast.MakeText(Application.Context, "Changed", ToastLength.Long).Show();
     //throw new NotImplementedException();
 }
Exemplo n.º 35
0
 public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
 {
     Owner.ShowToast("Saved: " + Owner.mFile);
     Log.Debug(TAG, Owner.mFile.ToString());
     Owner.UnlockFocus();
 }
 public override void OnConfigureFailed(CameraCaptureSession session)
 {
 }
 public override void OnCaptureProgressed(CameraCaptureSession session, CaptureRequest request, CaptureResult partialResult)
 {
     //base.OnCaptureProgressed(session, request, partialResult);
     Log.Debug(TAG, "Partial result");
 }
 public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
 {
     OnCaptureCompletedAction?.Invoke(session);
 }
		public override void OnConfigureFailed (CameraCaptureSession session)
		{
			if (null != fragment.Activity) 
				Toast.MakeText (fragment.Activity, "Failed", ToastLength.Short).Show ();
		}
 public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
 => OnCompleted?.Invoke(result);
			public override void OnCaptureCompleted (CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
			{
				if (Fragment != null && File != null)
				{
					Activity activity = Fragment.Activity;
					if (activity != null)
					{
						Toast.MakeText(activity, "Saved: " + File.ToString(), ToastLength.Short).Show();
						Fragment.StartPreview ();
					}
				}
			}
Exemplo n.º 42
0
 public CaptureWrapper(CameraCaptureSession session, CameraCaptureSession.CaptureCallback captureCallback)
 {
     _session         = session;
     _captureCallback = captureCallback;
 }
		/// <summary>
		/// Starts the camera previe
		/// </summary>
		private void StartPreview()
		{
			if (mCameraDevice == null || !mTextureView.IsAvailable || mPreviewSize == null) {
				return;
			}
			try 
			{
				SurfaceTexture texture = mTextureView.SurfaceTexture;
				System.Diagnostics.Debug.Assert( texture != null );

				// We configure the size of the default buffer to be the size of the camera preview we want
				texture.SetDefaultBufferSize(mPreviewSize.Width, mPreviewSize.Height);

				// This is the output Surface we need to start the preview
				Surface surface = new Surface(texture);

				// We set up a CaptureRequest.Builder with the output Surface
				mPreviewBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
				mPreviewBuilder.AddTarget(surface);

				// Here, we create a CameraCaptureSession for camera preview.
				mCameraDevice.CreateCaptureSession(new List<Surface>() { surface }, 
					new CameraCaptureStateListener() 
					{ 
						OnConfigureFailedAction = (CameraCaptureSession session) => 
						{
							Activity activity = Activity;
							if (activity != null)
							{
								Toast.MakeText(activity, "Failed", ToastLength.Short).Show();
							}
						},
						OnConfiguredAction = (CameraCaptureSession session) =>
						{
							mPreviewSession = session;
							UpdatePreview ();
						}
					},
					null);


			}
			catch (Exception ex) {
				Log.WriteLine (LogPriority.Info, "Camera2BasicFragment", ex.StackTrace);
			}
		}
Exemplo n.º 44
0
 public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
 {
     _owner.OnCaptureComplete();
 }
Exemplo n.º 45
0
        private void OnConfigured(CameraCaptureSession session)
        {
            // The camera is already closed
            if (null != CameraDevice)
            {

                // When the session is ready, we start displaying the preview.
                _captureSession = session;

                try
                {
                    // Auto focus should be continuous for camera preview.
                    _previewRequestBuilder.Set(CaptureRequest.ControlAfMode, new Integer((int)ControlAFMode.ContinuousPicture));
                    // Flash is automatically enabled when necessary.
                    _previewRequestBuilder.Set(CaptureRequest.ControlAeMode, new Integer((int)ControlAEMode.OnAutoFlash));

                    // Finally, we start displaying the camera preview.
                    _previewRequest = _previewRequestBuilder.Build();
                    _captureSession.SetRepeatingRequest(_previewRequest, _captureCallback, _backgroundHandler);
                }
                catch (CameraAccessException e)
                {
                    e.PrintStackTrace();
                }
            }
        }
Exemplo n.º 46
0
 public override void OnCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure failure)
 {
     _owner.OnError("Capture Failed: " + failure.ToString());
 }
 public override void OnCaptureProgressed(CameraCaptureSession session, CaptureRequest request, CaptureResult partialResult)
 {
     Process(partialResult);
 }
 public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
 {
     Owner.ShowToast("Saved: " + Owner.mFile);
     Log.Debug(TAG, Owner.mFile.ToString());
     Owner.UnlockFocus();
 }