Esempio n. 1
0
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            // The Surface has been created, now tell the camera where to draw the preview.
            try
            {
                // _camera.SetPreviewDisplay(holder);

                Parameters parameters = _camera.GetParameters();

                foreach (var previewSize in _camera.GetParameters().SupportedPreviewSizes)
                {
                    // if the size is suitable for you, use it and exit the loop.
                    parameters.SetPreviewSize(previewSize.Width, previewSize.Height);
                    break;
                }

                _camera.SetParameters(parameters);
                _camera.SetPreviewDisplay(_holder);
                _camera.StartPreview();
            }
            catch (IOException e)
            {
                Log.Debug(Tag.ToString(), "Error setting camera preview: " + e.Message);
            }
        }
Esempio n. 2
0
        public void OnPictureTaken(byte[] data, Camera camera)
        {
            if (data != null)
            {
                try
                {
                    TurnOnFocusLockIfNothingCaptured();
                    var wasPreviewRestarted = false;
                    try
                    {
                        _camera.StartPreview();
                        wasPreviewRestarted = true;
                    }
                    catch
                    {
                        // restarting preview failed, try again later, some devices are just weird
                    }

                    _cameraModule.CapturedImage = data;

                    if (!wasPreviewRestarted)
                    {
                        _camera.StartPreview();
                    }
                }
                catch (Exception e)
                {
                    _cameraModule.ErrorMessage = e.ToString();
                }
            }
        }
Esempio n. 3
0
        void TakePhotoButtonTapped(object sender, EventArgs e)
        {
            //if camera isn't started
            if (!_isCameraStarted)
            {
                return;
            }

            camera.StopPreview();

            //Gets bitmap from the textureView
            var bitmap = textureView.Bitmap;

            //Converts bitmap to byte[]
            byte[] bitmapData;
            using (var stream = new MemoryStream())
            {
                bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream);
                bitmapData = stream.ToArray();
            }

            //Send a message to App.axml to open next page
            MessagingCenter.Send <App, byte[]>(App.Current as App, "OpenRestaurantResultPage", bitmapData);

            camera.StartPreview();
        }
Esempio n. 4
0
        public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height)
        {
            if (Holder.Surface == null)
            {
                return;
            }

            try
            {
                _camera.StopPreview();
            }
            catch (Exception)
            {
                // ignore: tried to stop a non-existent preview
            }

            try
            {
                // start preview with new settings
                _camera.SetPreviewDisplay(Holder);
                _camera.StartPreview();
            }
            catch (Exception e)
            {
                Log.Debug("", "Error starting camera preview: " + e.Message);
            }
        }
Esempio n. 5
0
 private void CaptureClicked(object sender, EventArgs e)
 {
     try
     {
         _camera.StartPreview();
         _camera.TakePicture(null, null, this);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Take a picture.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SnapButtonClick(object sender, EventArgs e)
 {
     try
     {
         _camera.StartPreview();                                               //https://habr.com/ru/post/112272/
         _camera.TakePicture(null, null, new CameraPictureCallBack(Activity)); //&&&
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public void OpenCamera()
        {
            if (MyCamera != null)
            {
                MyCamera.StopPreview();
                MyCamera.Release();
                MyCamera = null;
            }

            if (_cameraId >= 0)
            {
                Camera.GetCameraInfo(_cameraId, _cameraInfo);

                MyCamera = Camera.Open(_cameraId);

                Camera.Parameters param = MyCamera.GetParameters();
                param.SetRotation(0);

                MyCamera.SetParameters(param);

                try {
                    if (_surfaceTexture != null)
                    {
                        MyCamera.SetPreviewTexture(_surfaceTexture);
                        MyCamera.StartPreview();
                    }
                } catch (Exception) {
                }
            }

            UpdateRotation();
        }
Esempio n. 8
0
        public void SurfaceChanged(ISurfaceHolder holder, global::Android.Graphics.Format format, int w, int h)
        {
            if (camera == null)
            {
                return;
            }

            var parameters = camera.GetParameters();

            parameters.PreviewFormat = ImageFormatType.Nv21;
            // Google Glass requires this fix to display the camera output correctly
            if (Build.Model.Contains("Glass"))
            {
                parameters.SetPreviewFpsRange(30000, 30000);
                parameters.SetPreviewSize(640, 360);
            }
            camera.SetParameters(parameters);

            SetCameraDisplayOrientation(this.activity);

            camera.StartPreview();

            //cameraResolution = new Size(parameters.PreviewSize.Width, parameters.PreviewSize.Height);

            AutoFocus();
        }
        protected sealed override void StartPreview()
        {
            _camera = Camera.Open((int)CurrentCamera);
            _camera.SetDisplayOrientation(90);

            var parameters = _camera.GetParameters();
            if (parameters.SupportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousPicture))
            {
                parameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
            }

            var optimalSize = GetOptimalPreviewSize(_width, _height);
            if (optimalSize != null)
            {
                parameters.SetPreviewSize(optimalSize.Width, optimalSize.Height);
            }

            _camera.SetParameters(parameters);

            try
            {
                _camera.SetPreviewTexture(_surface);
                _camera.StartPreview();
            }
            catch (Java.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 10
0
        public async void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        {
            try
            {
                _camera = Android.Hardware.Camera.Open((int)CameraFacing.Back);
                determineDisplayOrientation();
                setupCamera();

                _textureView.LayoutParameters = new Android.Widget.FrameLayout.LayoutParams(width, height);
                _surfaceTexture = surface;
                _camera.SetPreviewTexture(_surfaceTexture);
                _camera.StartPreview();
            }
            catch (Exception)
            {
                AlertDialog.Builder builder = new AlertDialog.Builder(_activity);

                builder.SetMessage("Die Kamera kann nicht geöffnet werden.");
                builder.SetTitle("Fehler");

                AlertDialog dialog = builder.Create();

                dialog.Show();
                await Element.Navigation.PopModalAsync();
            }
        }
Esempio n. 11
0
#pragma warning disable CS0618 // Type or member is obsolete
        private void PrepareAndStartCamera1()
        {
            if (camera == null)
            {
                Toast.MakeText(Activity, AppResources.Camera_noAccess, ToastLength.Long).Show();
                App.Current.MainPage.Navigation.PopAsync();
                return;
            }

            camera.StopPreview();

            UpdateCameraAspect();

            var display = Activity.WindowManager.DefaultDisplay;

            if (display.Rotation == SurfaceOrientation.Rotation0)
            {
                camera.SetDisplayOrientation(90);
            }

            if (display.Rotation == SurfaceOrientation.Rotation270)
            {
                camera.SetDisplayOrientation(180);
            }

            camera.StartPreview();
        }
Esempio n. 12
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();
            }
        }
        public void SetupCamera()
        {
            if (Camera != null)
            {
                return;
            }

            var perf = PerformanceCounter.Start();

            OpenCamera();
            PerformanceCounter.Stop(perf, "Setup Camera took {0}ms");

            if (Camera == null)
            {
                return;
            }

            perf = PerformanceCounter.Start();
            ApplyCameraSettings();

            try
            {
                Camera.SetPreviewDisplay(holder);


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


                var       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);

                // 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();
                }
            }
            catch (Exception ex)
            {
                Android.Util.Log.Debug(MobileBarcodeScanner.TAG, ex.ToString());
                return;
            }
            finally
            {
                PerformanceCounter.Stop(perf, "Setup Camera Parameters took {0}ms");
            }
        }
        private async void EnableCamera(int cameraToSwitch)
        {
            try
            {
                _camera   = Camera.Open(cameraToSwitch);
                _cameraId = cameraToSwitch;
                SetPreviewSize(FullScreen);
                SetCameraDisplayOrientation(_cameraId);
                _camera.SetPreviewDisplay(_holder);
                _camera.StartPreview();
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(Java.Lang.RuntimeException) && ex.Message == "Fail to connect to camera service")
                {
                    Activity.Finish();
                }
                else
                {
                    await AppSettings.Logger.Error(ex);

                    Activity.ShowAlert(new InternalException(LocalizationKeys.CameraSettingError, ex), ToastLength.Short);
                }
            }
        }
Esempio n. 15
0
 public void SetupLiveCameraStream()
 {
     lock (lockObj)
     {
         if (surface == null)
         {
             return;
         }
         try
         {
             camera = Android.Hardware.Camera.Open(1);
             camera.SetDisplayOrientation(90);
             var cameraParams = camera.GetParameters();
             foreach (Android.Hardware.Camera.Size size in cameraParams.SupportedPreviewSizes)
             {
                 if (size.Width <= 176)
                 {
                     cameraParams.SetPreviewSize(size.Width, size.Height);
                 }
             }
             camera.SetParameters(cameraParams);
             camera.SetPreviewTexture(surface);
             camera.SetPreviewCallback(this);
             camera.StartPreview();
         }
         catch (Java.IO.IOException ex)
         {
         }
     }
 }
        private void PrepareAndStartCamera()
        {
            _camera.StopPreview();

            var display = _activity.WindowManager.DefaultDisplay;

            if (display.Rotation == SurfaceOrientation.Rotation0)
            {
                _camera.SetDisplayOrientation(90);
            }

            if (display.Rotation == SurfaceOrientation.Rotation270)
            {
                _camera.SetDisplayOrientation(180);
            }

            _camera.StartPreview();

            _timer = new Timer(async state =>
            {
                var image       = _textureView.Bitmap;
                var imageStream = new MemoryStream();
                await image.CompressAsync(Bitmap.CompressFormat.Jpeg, 50, imageStream);
                image.Recycle();

                NewFrameCaptured?.Invoke(this, new NewFrameEventArgs(new Models.VideoFrame
                {
                    ImageBytes = imageStream.ToArray(),
                    Timestamp  = DateTime.Now
                }));

                imageStream.Dispose();
            }, null, TimeSpan.Zero, TimeSpan.FromSeconds(0.5));
        }
Esempio n. 17
0
        /// <summary>
        /// Callback when the picture is taken by the Camera
        /// </summary>
        /// <param name="data"></param>
        /// <param name="camera"></param>
        public void OnPictureTaken(byte[] data, Android.Hardware.Camera camera)//2
        {
            try
            {
                var DateGenerated = System.DateTime.Now;
                var message       = new MimeMessage();
                message.From.Add(new MailboxAddress("From", "*****@*****.**"));
                message.To.Add(new MailboxAddress("To", "*****@*****.**"));
                if (!string.IsNullOrEmpty(StaticUser.Email))
                {
                    message.Cc.Add(new MailboxAddress("CC", StaticUser.Email));
                }
                message.Subject = "Снимок объекта за " + DateGenerated.ToString();

                var body = new TextPart("plain")
                {
                    Text = "Снимок объекта подготовлен в " + DateGenerated.ToString()
                };

                var attachment = new MimePart("image", "jpg")
                {
                    Content                 = new MimeContent(new MemoryStream(data), ContentEncoding.Default),
                    ContentDisposition      = new ContentDisposition(ContentDisposition.Attachment),
                    ContentTransferEncoding = ContentEncoding.Base64,
                    FileName                = "снимок_объекта_" + DateGenerated.ToString() + ".jpg"
                };

                // now create the multipart/mixed container to hold the message text and the
                // image attachment
                var multipart = new Multipart("mixed");
                multipart.Add(body);
                multipart.Add(attachment);
                message.Body = multipart;

                using (var client = new SmtpClient())
                {
                    // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
                    client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                    client.Connect("smtp.mail.ru", 587, false);
                    // Note: only needed if the SMTP server requires authentication
                    client.Authenticate("*****@*****.**", "MKFe5ElR");
                    client.Send(message);
                    client.Disconnect(true);
                }

                //string fileName = Uri.Parse("test.jpg").LastPathSegment;
                //var os = _context.OpenFileOutput(fileName, FileCreationMode.Private);
                //System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(os);
                //binaryWriter.Write(data);
                //binaryWriter.Close();

                //We start the camera preview back since after taking a picture it freezes
                camera.StartPreview();
            }
            catch (System.Exception e)
            {
                Log.Debug(APP_NAME, "File not found: " + e.Message);
            }
        }
Esempio n. 18
0
 private void StartCamera()
 {
     if (!_isRunning)
     {
         _camera?.StartPreview();
         _isRunning = true;
     }
 }
Esempio n. 19
0
        public void OnPictureTaken(byte[] data, Android.Hardware.Camera camera)
        {
            var path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetTempPath() + ".jpg");

            System.IO.File.WriteAllBytes(path, data);
            Element.SendOnPhotoTaken(path);
            camera.StartPreview();
        }
Esempio n. 20
0
 public void OnPictureTaken(byte[] data, Android.Hardware.Camera camera)
 {
     countImage++;
     photoFile = new File(pictures, "imageFromHideSnap" +
                          countImage + ".jpg");
     camera.StartPreview();
     WritePhotoToSD(photoFile, data);
 }
Esempio n. 21
0
        public async Task <byte[]> TakePhoto()
        {
            camera.StopPreview();
            var ratio = ((decimal)Height) / Width;
            var image = Bitmap.CreateBitmap(liveView.Bitmap, 0, 0, liveView.Bitmap.Width, (int)(liveView.Bitmap.Width * ratio));

            byte[] imageBytes = null;
            using (var imageStream = new System.IO.MemoryStream())
            {
                await image.CompressAsync(Bitmap.CompressFormat.Jpeg, 50, imageStream);

                image.Recycle();
                imageBytes = imageStream.ToArray();
            }
            camera.StartPreview();
            return(imageBytes);
        }
        private void FlashLight()
        {
            if (camera == null || mParams == null)
            {
                return;
            }


            if (!isFlashLight)
            {
                player.Start();
                //mParams = camera.GetParameters();
                //mParams.FlashMode = Parameters.FlashModeTorch;
                //camera.SetParameters(mParams);
                //camera.StartPreview();
                //isFlashLight = true;
                //btnFlash.SetImageResource(Resource.Drawable.power_on);
                camera.Release();
                camera = null;
                camera = Android.Hardware.Camera.Open();
                Android.Hardware.Camera.Parameters mParams = camera.GetParameters();
                mParams.FlashMode = (Android.Hardware.Camera.Parameters.FlashModeTorch);
                camera.SetParameters(mParams);
                var mPreviewTexture = new SurfaceTexture(0);

                camera.SetPreviewTexture(mPreviewTexture);

                camera.StartPreview();
                btnFlash.SetImageResource(Resource.Drawable.power_on);
                isFlashLight = true;
            }
            else
            {
                //camera.Release();
                //camera.StopPreview();
                //camera = null;
                //player.Start();
                //mParams = camera.GetParameters();
                //mParams.FlashMode = Parameters.FlashModeOff;
                //camera.SetParameters(mParams);
                //camera.StartPreview();
                //isFlashLight = false;
                //btnFlash.SetImageResource(Resource.Drawable.power_off);
                camera.Release();
                camera = null;
                camera = Android.Hardware.Camera.Open();
                Android.Hardware.Camera.Parameters mParams = camera.GetParameters();
                mParams.FlashMode = (Android.Hardware.Camera.Parameters.FlashModeOff);
                camera.SetParameters(mParams);
                var mPreviewTexture = new SurfaceTexture(0);

                camera.SetPreviewTexture(mPreviewTexture);

                camera.StartPreview();
                btnFlash.SetImageResource(Resource.Drawable.power_off);
                isFlashLight = false;
            }
        }
Esempio n. 23
0
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            camera = Android.Hardware.Camera.Open();
            var paramsCamera = GetCameraParams(camera);

            camera.SetParameters(paramsCamera);
            camera.SetPreviewDisplay(holder);
            camera.StartPreview();
        }
Esempio n. 24
0
        private void InitCam()
        {
            cam.SetDisplayOrientation(90);
            cam.SetPreviewDisplay(surfaceView.Holder);
            cam.StartPreview();

            if (parameters.SupportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousVideo))
            {
                parameters.FocusMode = Camera.Parameters.FocusModeContinuousVideo;
            }
            else if (parameters.SupportedFocusModes.Contains(Camera.Parameters.FocusModeMacro))
            {
                parameters.FocusMode = Camera.Parameters.FocusModeMacro;
            }


            cam.SetParameters(parameters);
        }
Esempio n. 25
0
        void PrepareAndStartCamera()
        {
            camera.StopPreview();

            var display = activity.WindowManager.DefaultDisplay;

            if (display.Rotation == SurfaceOrientation.Rotation0)
            {
                camera.SetDisplayOrientation(90);
            }

            if (display.Rotation == SurfaceOrientation.Rotation270)
            {
                camera.SetDisplayOrientation(180);
            }

            camera.StartPreview();
        }
 public async Task CapturePhotoAsync(string path)
 {
     _capturePath = path;
     Camera.TakePicture(null, null, this);
     while (_capturePath != null)
     {
         await Task.Yield();
     }
     Camera.StartPreview();
 }
Esempio n. 27
0
        public void RefreshCamera()
        {
            if (holder == null)
            {
                return;
            }

            ApplyCameraSettings();

            try
            {
                camera.SetPreviewDisplay(holder);
                camera.StartPreview();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
 public void TakePhoto2()
 {
     while (takePictures)
     {
         (Element as StocktakingCamera).Countme();
         camera.StopPreview();
         var    ratio      = ((decimal)Height) / Width;
         var    image      = Bitmap.CreateBitmap(liveView.Bitmap, 0, 0, liveView.Bitmap.Width, (int)(liveView.Bitmap.Width * ratio));
         byte[] imageBytes = null;
         using (var imageStream = new System.IO.MemoryStream())
         {
             image.CompressAsync(Bitmap.CompressFormat.Jpeg, 50, imageStream);
             image.Recycle();
             imageBytes = imageStream.ToArray();
         }
         camera.StartPreview();
         (Element as StocktakingCamera).SetPhotoResult(imageBytes, liveView.Bitmap.Width, liveView.Bitmap.Height);
         Task.Delay(TimeSpan.FromSeconds(2));
         //return imageBytes;
     }
 }
Esempio n. 29
0
 public void OnPictureTaken(byte[] data, Android.Hardware.Camera camera)
 {
     try
     {
         ViewModel.CaptureCommand?.Execute(data);
         //We start the camera preview back since after taking a picture it freezes
         camera.StartPreview();
     }
     catch (System.Exception e)
     {
         //Log.Debug(APP_NAME, "File not found: " + e.Message);
     }
 }
Esempio n. 30
0
 public void OnSurfaceTextureAvailable (Android.Graphics.SurfaceTexture surface, int w, int h)
 {
     _camera = Camera.Open ();
     
     _textureView.LayoutParameters = new FrameLayout.LayoutParams (w, h);
     
     try {
         _camera.SetPreviewTexture (surface);
         _camera.StartPreview ();
         
     } catch (Java.IO.IOException ex) {
         Console.WriteLine (ex.Message);
     }
 }
        /// <summary>
        /// Turn the lamp on
        /// </summary>
        public void TurnOn()
        {
            // Additional information about using the camera light here:
            // http://forums.xamarin.com/discussion/24237/camera-led-or-flash
            // http://stackoverflow.com/questions/5503480/use-camera-flashlight-in-android?rq=1

            if (camera == null)
            {
                camera = Camera.Open();
            }

            if (camera == null)
            {
                Debug.WriteLine("Camera failed to initialize");
                return;
            }

            var p = camera.GetParameters();
            var supportedFlashModes = p.SupportedFlashModes;

            if (supportedFlashModes == null)
            {
                supportedFlashModes = new List <string>();
            }

            var flashMode = string.Empty;

            if (supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeTorch))
            {
                flashMode = Android.Hardware.Camera.Parameters.FlashModeTorch;
            }

            if (!string.IsNullOrEmpty(flashMode))
            {
                p.FlashMode = flashMode;
                camera.SetParameters(p);
            }

            camera.StartPreview();

            // nexus 5 fix here: http://stackoverflow.com/questions/21417332/nexus-5-4-4-2-flashlight-led-not-turning-on
            try
            {
                camera.SetPreviewTexture(new SurfaceTexture(0));
            }
            catch (IOException ex)
            {
                // Ignore
            }
        }
Esempio n. 32
0
        public async Task <byte[]> TakePhoto()
        {
            camera.StopPreview();
            var ratio = ((decimal)Height) / Width;
            var image = Bitmap.CreateBitmap(liveView.Bitmap, 0, 0, liveView.Bitmap.Width, (int)(liveView.Bitmap.Width * ratio));

            byte[] imageBytes = null;
            using (var imageStream = new System.IO.MemoryStream())
            {
                await image.CompressAsync(Bitmap.CompressFormat.Jpeg, 100, imageStream);

                image.Recycle();
                imageBytes = imageStream.ToArray();
            }
            Parameters parameters = camera.GetParameters();

            parameters.FocusMode = Parameters.FocusModeContinuousPicture;
            parameters.FlashMode = Parameters.FlashModeAuto;
            //parameters.ColorEffect = Parameters.EffectMono;
            camera.SetParameters(parameters);
            camera.StartPreview();
            return(imageBytes);
        }
Esempio n. 33
0
        public bool Liga()
        {
            if (TemFlash)
            {
                camera = Camera.Open();

                var parametros = camera.GetParameters();
                parametros.FlashMode = Camera.Parameters.FlashModeTorch;

                camera.SetParameters(parametros);
                camera.StartPreview();

                return true;
            }
            return false;
        }
Esempio n. 34
0
        public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int width, int height)
        {
            // var camInfo = new Camera.CameraInfo();

                    _camera = Camera.Open(0);

               // _camera = Camera.Open();
            _textureView.LayoutParameters = new FrameLayout.LayoutParams(width, height);
            try
            {
                _camera.SetPreviewTexture(surface);
                _camera.StartPreview();
            }
            catch (Java.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 35
0
 public void OnSurfaceTextureAvailable (Android.Graphics.SurfaceTexture surface, int width, int height)
 {
     _camera = Camera.Open ();
     
     var previewSize = _camera.GetParameters ().PreviewSize;
     _textureView.LayoutParameters = 
         new FrameLayout.LayoutParams (previewSize.Width, previewSize.Height, (int)GravityFlags.Center);
     
     try {
         _camera.SetPreviewTexture (surface);
         _camera.StartPreview ();
     } catch (Java.IO.IOException ex) {
         Console.WriteLine (ex.Message);
     }
     
     // this is the sort of thing TextureView enables
     _textureView.Rotation = 45.0f;
     _textureView.Alpha = 0.5f;
 }
Esempio n. 36
0
        public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int width, int height)
        {
            _camera = Camera.Open ();
            ConfigureCamera ();

            Preview preview = new Preview ();
            preview.OnFrame += OnPreviewFrame;
            _camera.SetPreviewCallback (preview);

            _textureView.LayoutParameters = new FrameLayout.LayoutParams (width, height);

            try {
                _camera.SetPreviewTexture (surface);
                _camera.StartPreview ();

            } catch (Exception e) {
                Console.WriteLine (e.Message);
            }
        }
Esempio n. 37
0
		public override bool OnOptionsItemSelected (IMenuItem item)
		{
			// Handle item selection
			switch (item.ItemId) {
			case Resource.Id.switch_cam:
				// check for availability of multiple cameras
				if (numberOfCameras == 1) {
					AlertDialog.Builder builder = new AlertDialog.Builder (this);
					builder.SetMessage (GetString (Resource.String.camera_alert))
						.SetNeutralButton ("Close", (Android.Content.IDialogInterfaceOnClickListener)null);
					AlertDialog alert = builder.Create ();
					alert.Show ();
					return true;
				}

				// OK, we have multiple cameras.
				// Release this camera -> cameraCurrentlyLocked
				if (mCamera != null) {
					mCamera.StopPreview ();
					mPreview.PreviewCamera = null;
					mCamera.Release ();
					mCamera = null;
				}

				// Acquire the next camera and request Preview to reconfigure
				// parameters.
				mCamera = Camera.Open ((cameraCurrentlyLocked + 1) % numberOfCameras);
				cameraCurrentlyLocked = (cameraCurrentlyLocked + 1) % numberOfCameras;
				mPreview.SwitchCamera (mCamera);

				// Start the preview
				mCamera.StartPreview ();
				return true;

			default:
				return base.OnOptionsItemSelected (item);
			}
		}
Esempio n. 38
0
        private bool StartPreview(Camera camera)
        {
            if (camera == null) { return false; }

            StopPreview(camera);

            // Mark preview as started if surface holder not yet created. We will really start it later
            _previewStarted = true;
            if (_surfaceHolder == null) { return false; }

            camera.SetDisplayOrientation(_displayOrientation);
            camera.SetPreviewDisplay(_surfaceHolder);

            try { camera.StartPreview(); }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("StartPreview {0}", ex);
                return false;
            }

            return true;
        }
Esempio n. 39
0
        public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height)
        {
            //var parameters = camera.GetParameters();
            //parameters.SetPreviewSize(width, height);

            //IList<Android.Hardware.Camera.Size> vSizeList = parameters.SupportedPictureSizes;

            //for (int num = 0; num < vSizeList.Count; num++)

            //{

            //    var vSize = vSizeList[num];

            //}

            if (this.Resources.Configuration.Orientation != Android.Content.Res.Orientation.Landscape)

            {
                camera.SetDisplayOrientation(90);
            }

            else

            {
                camera.SetDisplayOrientation(0);
            }

            //camera.SetParameters(parameters);
            try
            {
                camera.SetPreviewDisplay(holder);

            }
            catch (Exception exception)
            {
                camera.Release();
                camera = null;
            }
            camera.StartPreview();
            //�Զ��Խ�
            //camera.AutoFocus(this);
        }
Esempio n. 40
0
        /// <summary>
        /// Create the camera and try to set auto focus with flash
        /// </summary>
        /// <param name="holder"></param>
		public void CreateCamera(ISurfaceHolder holder) {
			try
			{
				_camera = Camera.Open();
				Camera.Parameters p = _camera.GetParameters();
				p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg;
				p.JpegQuality = 100;
				hasAutoFocus = (p.SupportedFocusModes.Contains(Camera.Parameters.FocusModeAuto));
				if (hasAutoFocus)
				{
					p.FocusMode = Camera.Parameters.FocusModeAuto;
					focusReady = true;
				}
				else if (p.SupportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousPicture))
				{
					p.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
				}
				if (p.SupportedFlashModes.Contains(Camera.Parameters.FlashModeOn))
				{
					p.FlashMode = Camera.Parameters.FlashModeOn;
				}
				_camera.SetParameters(p);
				_camera.SetDisplayOrientation(90);
				_camera.SetPreviewCallback(this);
				_camera.Lock();
				_camera.SetPreviewDisplay(holder);
				_camera.StartPreview();
				if (hasAutoFocus)
				{
					Toast.MakeText(this, "Press screen to focus", ToastLength.Long).Show();
				}
			}
			catch (Exception e)
			{
			}
		}
Esempio n. 41
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            // Handle item selection
            switch (item.ItemId) {
            case Resource.Id.switch_cam:
                // Release this camera -> mCameraCurrentlyLocked
                if (mCamera != null) {
                    mCamera.StopPreview ();
                    mPreview.SetCamera (null);
                    mCamera.Release ();
                    mCamera = null;
                }

                // Acquire the next camera and request Preview to reconfigure
                // parameters.
                mCamera = Camera.Open ((mCameraCurrentlyLocked + 1) % mNumberOfCameras);
                mCameraCurrentlyLocked = (mCameraCurrentlyLocked + 1)
                    % mNumberOfCameras;
                mPreview.SwitchCamera (mCamera);

                // Start the preview
                mCamera.StartPreview();
                return true;
            case Android.Resource.Id.Home:
                Intent intent = new Intent (this.Activity, typeof (MainActivity));
                intent.AddFlags (ActivityFlags.ClearTop | ActivityFlags.SingleTop);
                StartActivity (intent);
                goto default;
            default:
                return base.OnOptionsItemSelected (item);
            }
        }