Ejemplo n.º 1
0
 // AutoFocusのコールバック
 public void OnAutoFocus(bool success, AndroidCamera camera)
 {
     if (isTakeEnabled)
     {
         m_Camera.TakePicture(null, null, this);
     }
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            if (SetCameraInstance() == true)
            {
                _camPreview = new CameraPreview(this, _camera, _cameraId);
            }
            else
            {
                Finish();
            }

            var preview = (RelativeLayout)FindViewById(Resource.Id.preview_layout);

            preview.AddView(_camPreview);

            var previewLayout = (RelativeLayout.LayoutParams)_camPreview.LayoutParameters;

            previewLayout.Width          = ViewGroup.LayoutParams.MatchParent;
            previewLayout.Height         = ViewGroup.LayoutParams.MatchParent;
            _camPreview.LayoutParameters = previewLayout;

            var captureButton = (Button)FindViewById(Resource.Id.button_capture);

            captureButton.Click += (s, e) =>
            {
                _camera.TakePicture(null, null, _camPreview);
            };

            // at last, a call to set the right layout of the elements (like the button)
            // depending on the screen orientation (if it's changeable).
            FixElementsPosition(Resources.Configuration.Orientation);
        }
Ejemplo n.º 3
0
 private async Task TakePicture()
 {
     await Task.Factory.StartNew(() =>
     {
         System.Threading.Thread.Sleep(1000);
         _camera.TakePicture(this, this, this);
     });
 }
Ejemplo n.º 4
0
 public void TakePicture()
 {
     lock (_camera) {
         if (picInProgress)
         {
             return;
         }
         _camera.TakePicture(null, null, this);
         picInProgress = true;
     }
 }
Ejemplo n.º 5
0
 public void OnAutoFocus(bool autoFocused, Camera camera)
 {
     if (isTakePhoto && autoFocused)
     {
         camera.TakePicture(new ShutterCallback(), null, new JpegCallback(this.cameraPreview));
     }
     else
     {
         camera.AutoFocus(new AutofocusCallBack(cameraPreview));  // TODO: Verify No Memory Leak On Failure
     }
 }
Ejemplo n.º 6
0
 private void CaptureClicked(object sender, EventArgs e)
 {
     try
     {
         camera.StartPreview();
         camera.TakePicture(null, null, this);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Ejemplo n.º 7
0
 public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int w, int h)
 {
     _camera = Android.Hardware.Camera.Open();
     _textureView.LayoutParameters = new FrameLayout.LayoutParams(w, h);
     _camera.SetPreviewTexture(surface);
     _camera.StartPreview();
     try
     {
         Toast.MakeText(this, "About to take picture", ToastLength.Short).Show();
         _camera.TakePicture(null, null, this);
         Toast.MakeText(this, "Finished pic", ToastLength.Short).Show();
         _camera = Android.Hardware.Camera.Open();
         _textureView.LayoutParameters = new FrameLayout.LayoutParams(w, h);
         _camera.SetPreviewTexture(surface);
         _camera.StartPreview();
         Toast.MakeText(this, "This shit again!", ToastLength.Short).Show();
     }
     catch (Exception e)
     {
         Toast.MakeText(this, e.ToString(), ToastLength.Long).Show();
     }
 }
Ejemplo n.º 8
0
 private void TakePicture()
 {
     camera.StartPreview();
     camera.TakePicture(null, null, this);
 }