コード例 #1
0
 /// <summary>
 /// 지정된 주기로 포커싱합니다.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnTick(object sender, ElapsedEventArgs e)
 {
     if (_timer.Enabled)
     {
         _camera.AutoFocus(this);
     }
 }
コード例 #2
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
     }
 }
コード例 #3
0
        /**
         * In addition to calling {@link Camera#startPreview()}, it also
         * updates the preview display that could be changed in some situations
         * @param holder the current {@link SurfaceHolder}
         */

        private async void StartCameraPreview(ISurfaceHolder holder)
        {
            try
            {
                _camera.SetPreviewDisplay(holder);
                _camera.StartPreview();
                _camera.AutoFocus(null);
            }
            catch (Exception e)
            {
                Console.WriteLine($"startCameraPreview(): error starting camera preview, {e}");
            }
        }
コード例 #4
0
 private async void AutoFocus()
 {
     if (!(Element as VideoCameraPage).IsRecording)
     {
         if (!isFocus)
         {
             isFocus = true;
             await Task.Run(() =>
             {
                 camera.AutoFocus(this);
             });
         }
     }
 }
コード例 #5
0
 private async void AutoFocus()
 {
     if (!isFocus)
     {
         isFocus = true;
         progressBar.Visibility        = Android.Views.ViewStates.Visible;
         capturePhotoButton.Visibility = Android.Views.ViewStates.Invisible;
         await Task.Run(() =>
         {
             camera.AutoFocus(this);
         });
     }
     else
     {
     }
 }
コード例 #6
0
        /// <summary>
        /// 지정된 주기로 자동 포커스를 설정합니다.
        /// </summary>
        /// <param name="camera">대상 카메라</param>
        /// <param name="interval">자동 포커스 시간 간격(ms)</param>
        public AutoFocusCallback(AndroidCamera camera, int interval)
        {
            _camera = camera;

            _timer = new Timer()
            {
                Interval  = interval,
                Enabled   = false,
                AutoReset = true
            };
            _timer.Elapsed += OnTick;
            _timer.Start();

            this.Write($"AutoFocusCallback is created");

            try
            {
                _camera.AutoFocus(this);
            }
            catch (Exception ex)
            {
                this.Write($"Camera AutoFocus setting exception : {ex.Message}");
            }
        }
コード例 #7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Window.AddFlags(WindowManagerFlags.Fullscreen);             // 全画面表示に
            RequestWindowFeature(WindowFeatures.NoTitle);               // タイトルバーをなくす


            disp = WindowManager.DefaultDisplay;
            GetDisplaySize();


            FrameLayout rootView = new FrameLayout(ApplicationContext);

            SetContentView(rootView);

            m_TextureView = new TextureView(ApplicationContext);
            m_TextureView.SurfaceTextureListener = this;

            m_TextureView.Touch += (sender, e) => {
                if (e.Event.Action == MotionEventActions.Down)
                {
                    StartX = e.Event.GetX();
                    StartY = e.Event.GetY();
                }

                if (e.Event.Action == MotionEventActions.Move)
                {
                    var param = m_Camera.GetParameters();
                    var Zoom  = param.Zoom;

                    if (e.Event.GetY() > (StartY + 50))
                    {
                        Zoom--;
                        StartY = e.Event.GetY();
                    }
                    else if (e.Event.GetY() < (StartY - 50))
                    {
                        Zoom++;
                        StartY = e.Event.GetY();
                    }


                    if (Zoom > param.MaxZoom)
                    {
                        Zoom = param.MaxZoom;
                    }
                    if (Zoom < 1)
                    {
                        Zoom = 1;
                    }

                    param.Zoom = Zoom;
                    m_Camera.SetParameters(param);

                    Console.WriteLine("StartY:" + StartY +
                                      "\nNowY:" + e.Event.GetY() +
                                      "\nZoom" + Zoom);
                }
            };

            rootView.AddView(m_TextureView);

            Button button = new Button(ApplicationContext);

            button.Text             = "撮影";
            button.LayoutParameters = new ViewGroup.LayoutParams(200, 150);
            button.Clickable        = true;
            button.SetWidth(200);
            button.SetHeight(150);


            if (!isLandScapeMode())
            {
                button.SetX((DisplayWidth / 2) - 100);
                button.SetY(DisplayHeight - 300);
            }
            else
            {
                button.SetX((DisplayHeight / 2) - 100);
                button.SetY(DisplayWidth - 150);
            }

            button.Touch += (sender, e) => {
                if (e.Event.Action == MotionEventActions.Down)
                {
                    isTakeEnabled = false;
                    m_Camera.AutoFocus(this);
                }

                if ((!isTakeEnabled) && (e.Event.Action == MotionEventActions.Up))
                {
                    // 撮影中ではない & ボタンから指が離れた
                    if ((e.Event.RawX > button.GetX()) &&
                        (e.Event.RawX < (button.GetX() + ButtonWidth)) &&
                        (e.Event.RawY > button.GetY()) &&
                        (e.Event.RawY < (button.GetY() + ButtonHeight)))
                    {
                        // 指が離れた時にボタン上に指があった
                        isTakeEnabled = true;
                        m_Camera.AutoFocus(this);
                    }

                    Toast.MakeText(ApplicationContext,
                                   "ButtonX:" + button.GetX() +
                                   "\nButtonY:" + button.GetY() +
                                   "\nGetX:" + e.Event.RawX +
                                   "\nGetY:" + e.Event.RawY,
                                   ToastLength.Short).Show();
                }
            };

            rootView.AddView(button);

            m_LocationManager = (LocationManager)GetSystemService(Context.LocationService);
        }
コード例 #8
0
        void video_Touch(object sender, View.TouchEventArgs e)
        {
            if (e.Event.Action == MotionEventActions.Up && camera.GetParameters().SupportedFocusModes.Contains(Android.Hardware.Camera.Parameters.FocusModeAuto) && !focussing)
            {
                focussing = true;
                try
                {
                    camera.CancelAutoFocus();
                }
                catch
                {
                }

                float x         = e.Event.GetX();
                float y         = e.Event.GetY();
                Rect  touchRect = new Rect(
                    (int)(x - 70),
                    (int)(y - 70),
                    (int)(x + 70),
                    (int)(y + 70));
                Rect targetFocusRect = new Rect(
                    touchRect.Left * 2000 / View.Width - 1000,
                    touchRect.Top * 2000 / View.Height - 1000,
                    touchRect.Right * 2000 / View.Width - 1000,
                    touchRect.Bottom * 2000 / View.Height - 1000);

                List <Android.Hardware.Camera.Area> focusList = new List <Android.Hardware.Camera.Area>();
                Android.Hardware.Camera.Area        focusArea = new Android.Hardware.Camera.Area(targetFocusRect, 1000);
                focusList.Add(focusArea);

                Android.Hardware.Camera.Parameters param = camera.GetParameters();
                param.FocusAreas    = focusList;
                param.MeteringAreas = focusList;

                if (ViewCompat.GetLayoutDirection(focusring) == ViewCompat.LayoutDirectionRtl)
                {
                    focusring.LayoutParameters = new FrameLayout.LayoutParams(focusring.LayoutParameters)
                    {
                        MarginStart = Resources.DisplayMetrics.WidthPixels - ((int)x + (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics)), TopMargin = (int)y - (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics)
                    };
                }
                else
                {
                    focusring.LayoutParameters = new FrameLayout.LayoutParams(focusring.LayoutParameters)
                    {
                        MarginStart = (int)x - (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics), TopMargin = (int)y - (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics)
                    };
                }

                focusring.Visibility = ViewStates.Visible;

                Animation scaleup = AnimationUtils.LoadAnimation(Context, Resource.Animation.scaleup);
                scaleup.Interpolator = new DecelerateInterpolator();
                scaleup.Duration     = 300;
                inner_ring.StartAnimation(scaleup);

                Animation scaledown = AnimationUtils.LoadAnimation(Context, Resource.Animation.scaledown);
                scaledown.Duration     = 300;
                scaledown.Interpolator = new DecelerateInterpolator();
                outer_ring.StartAnimation(scaledown);

                //View.SetHaveTouch(true, touchRect);
                //drawingView.Invalidate();
                //        // Remove the square indicator after 1000 msec



                try
                {
                    camera.SetParameters(param);
                    camera.AutoFocus(this);
                    //drawingView.setHaveTouch(true, touchRect);
                    //drawingView.Invalidate();
                    // Remove the square indicator after 1000 msec
                }
                catch (Exception ef)
                {
                    Console.WriteLine(ef);
                    focussing = false;
                }

                Handler handler = new Handler();
                handler.PostDelayed(() => {
                    focusring.Visibility = ViewStates.Invisible;
                }, 800);
            }
        }
コード例 #9
0
 private void AutofocusCalled(object sender, EventArgs e)
 {
     camera.AutoFocus(this);
 }