void AutoFocus(int x, int y, bool useCoordinates)
        {
            if (camera != null)
            {
                var cameraParams = camera.GetParameters();

                Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "AutoFocus Requested");

                // Cancel any previous requests
                camera.CancelAutoFocus();

                try {
                    // If we want to use coordinates
                    // Also only if our camera supports Auto focus mode
                    // Since FocusAreas only really work with FocusModeAuto set
                    if (useCoordinates &&
                        cameraParams.SupportedFocusModes.Contains(Camera.Parameters.FocusModeAuto))
                    {
                        // Let's give the touched area a 20 x 20 minimum size rect to focus on
                        // So we'll offset -10 from the center of the touch and then
                        // make a rect of 20 to give an area to focus on based on the center of the touch
                        x = x - 10;
                        y = y - 10;

                        // Ensure we don't go over the -1000 to 1000 limit of focus area
                        if (x >= 1000)
                        {
                            x = 980;
                        }
                        if (x < -1000)
                        {
                            x = -1000;
                        }
                        if (y >= 1000)
                        {
                            y = 980;
                        }
                        if (y < -1000)
                        {
                            y = -1000;
                        }

                        // Explicitly set FocusModeAuto since Focus areas only work with this setting
                        cameraParams.FocusMode = Camera.Parameters.FocusModeAuto;
                        // Add our focus area
                        cameraParams.FocusAreas = new List <Camera.Area> {
                            new Camera.Area(new Rect(x, y, x + 20, y + 20), 1000)
                        };
                        camera.SetParameters(cameraParams);
                    }

                    // Finally autofocus (weather we used focus areas or not)
                    camera.AutoFocus(this);
                } catch (Exception ex) {
                    Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "AutoFocus Failed: {0}", ex);
                }
            }
        }
Exemplo n.º 2
0
 public void AutoFocus()
 {
     if (camera != null)
     {
         if (!tokenSource.IsCancellationRequested)
         {
             Android.Util.Log.Debug("ZXING", "AutoFocus Requested");
             camera.AutoFocus(this);
         }
     }
 }
Exemplo n.º 3
0
 public void AutoFocus(int x, int y)
 {
     if (camera != null)
     {
         if (!tokenSource.IsCancellationRequested)
         {
             Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "AutoFocus Requested");
             try {
                 camera.AutoFocus(this);
             } catch (Exception ex) {
                 Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "AutoFocus Failed: {0}", ex);
             }
         }
     }
 }
Exemplo n.º 4
0
 // Start autofocus (used when continuous autofocus is disabled)
 public void autoFocus(Android.Hardware.Camera.IAutoFocusCallback callback)
 {
     if (camera != null)
     {
         try
         {
             setCameraFocusMode(Android.Hardware.Camera.Parameters.FocusModeAuto);
             camera.AutoFocus(callback);
         }
         catch (Exception e)
         {
             Log.Error(GetString(Resource.String.app_name), "Error: " + e.Message);
         }
     }
 }
Exemplo n.º 5
0
        public AutoFocusCallback(AndroidCamera camera)
        {
            timer = new Timer()
            {
                Interval  = 400,
                Enabled   = false,
                AutoReset = true
            };

            timer.Elapsed += (s, e) => {
                if (timer.Enabled)
                {
                    this.Debug("Autofocusing");
                    camera.AutoFocus(this);
                }
            };
        }
Exemplo n.º 6
0
 private void TapOnCamera(object sender, EventArgs e)
 {
     _camera.AutoFocus(this);
 }
Exemplo n.º 7
0
 private void TakePhotoButtonTapped(object sender, EventArgs e)
 {
     takePicture = true;
     UserDialogs.Instance.ShowLoading(title: "Please hold still...");
     camera.AutoFocus(this);
 }
Exemplo n.º 8
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Hide the window title and go fullscreen.
            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.AddFlags(WindowManagerFlags.Fullscreen);

            // Create our Preview view and set it as the content of our activity.
            mPreview = new CameraView(this);

            FrameLayout.LayoutParams tparams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent,
                                                                            ViewGroup.LayoutParams.WrapContent);                            //定义显示组件参数

            View   mainView  = View.Inflate(this, Resource.Layout.Main, null);
            Button btn       = mainView.FindViewById <Button> (Resource.Id.takepicb);
            Button enrollbtn = mainView.FindViewById <Button> (Resource.Id.enrollbtn);
            Button kechenbtn = mainView.FindViewById <Button> (Resource.Id.button1);

            Spinner spinner = mainView.FindViewById <Spinner> (Resource.Id.spinner1);

            tv      = mainView.FindViewById <TextView> (Resource.Id.statustext);
            tv.Text = "开始指纹识别。。。";
            result  = mainView.FindViewById <TextView> (Resource.Id.resulttext);

            Switch autoSw = mainView.FindViewById <Switch> (Resource.Id.switch1);

            iv        = mainView.FindViewById <ImageView> (Resource.Id.imageView1);
            frameView = mainView.FindViewById <TextView> (Resource.Id.textView1);

            tts = new TextToSpeech(this, this);

            FrameLayout fl = new FrameLayout(this);

            fl.AddView(mPreview);
            fl.AddView(mainView);

            //保持屏幕常亮
            Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);
            SetContentView(fl, tparams);

            // Initialize SourceAFIS
            Afis = new AfisEngine();
            // Look up the probe using Threshold = 10
            Afis.Threshold = 25;
            // Enroll some people
            database = new List <MyPerson>();
            lessons  = new List <MyLesson> ();

            if (System.IO.File.Exists(ImagePath + "lessons"))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                using (FileStream stream = File.OpenRead(ImagePath + "lessons"))
                    lessons = (List <MyLesson>)formatter.Deserialize(stream);
            }
            else
            {
                tv.Text = "无课程,请添加课程。。。";
            }

            List <string> lessonname = new List <string> ();

            foreach (MyLesson ml in lessons)
            {
                lessonname.Add(ml.name);
            }
            ArrayAdapter <string> adapter = new ArrayAdapter <string> (Application.Context, Android.Resource.Layout.SimpleSpinnerItem, lessonname);

            spinner.Adapter       = adapter;
            spinner.ItemSelected += delegate(object sender, AdapterView.ItemSelectedEventArgs e) {
                Spinner s = (Spinner)sender;
                nowLesson = s.GetItemAtPosition(e.Position).ToString();

                //判断数据库是否存在
                if (System.IO.File.Exists(ImagePath + nowLesson + ".dat"))
                {
                    tv.Text = "已载入" + nowLesson + "数据库,开始识别。。。";
                    BinaryFormatter formatterr = new BinaryFormatter();
                    Console.WriteLine("Reloading database...");
                    using (FileStream stream = File.OpenRead(ImagePath + nowLesson + ".dat"))
                        database = (List <MyPerson>)formatterr.Deserialize(stream);
                }
                else
                {
                    tv.Text  = "数据库" + nowLesson + "中无数据,请录入指纹。。。";
                    database = new List <MyPerson>();
                }

                //判断本课程今天的考勤是否已经建立
                todayisbuld = false;
                for (int i = 0; i < lessons.Count; i++)
                {
                    if (lessons[i].name.Equals(nowLesson))
                    {
                        //获取当前课程的数据库中的标号
                        nowLessonNum = i;
                        for (int j = 0; j < lessons[i].attendance.Count; j++)
                        {
                            DateTime nowTime = DateTime.Now;
                            if ((lessons[i].attendance[j].date.Year == nowTime.Year) &&
                                (lessons[i].attendance[j].date.Month == nowTime.Month) &&
                                (lessons[i].attendance[j].date.Day == nowTime.Day)
                                )
                            {
                                todayisbuld = true;
                                //如果本课程今天已经建立了考勤,则获取当前考勤的数据库标号
                                todayNum = j;
                                //校准考勤时间的日期到今天的课程设置时间,方便比较
                                //lessons[nowLessonNum].time = new DateTime(nowTime.Year,nowTime.Month,nowTime.Day,
                                //	lessons[nowLessonNum].time.Hour,lessons[nowLessonNum].time.Minute,0);
                            }
                        }
                    }
                }

                //如果没建立,就新建一个
                if (!todayisbuld)
                {
                    DateTime nowTime = DateTime.Now;
                    //校准考勤时间的日期到今天的课程设置时间,方便比较
                    //lessons[nowLessonNum].time = new DateTime(nowTime.Year,nowTime.Month,nowTime.Day,
                    //	lessons[nowLessonNum].time.Hour,lessons[nowLessonNum].time.Minute,0);

                    //新建今天的考勤
                    Attendance att = new Attendance(new DateTime(nowTime.Year, nowTime.Month, nowTime.Day,
                                                                 lessons[nowLessonNum].time.Hour, lessons[nowLessonNum].time.Minute, 0));
                    lessons[nowLessonNum].attendance.Add(att);
                    todayNum    = lessons[nowLessonNum].attendance.IndexOf(att);
                    todayisbuld = true;
                }
            };

            btn.Click += delegate {
                try{
                    auto = false;
                    mCamera.TakePicture(null, null, this);
                    //设置、输出相机参数
                    Android.Hardware.Camera.Parameters p = mCamera.GetParameters();
                    string s = p.Flatten();
                    Console.WriteLine(s);
                    //					p.Set("iso",100.ToString());
                    //					p.Set("jpeg-quality",100.ToString());
                    //					mCamera.SetParameters(p);

                    //输出支持的图片分辨率
                    //					IList<Android.Hardware.Camera.Size> ss =  p.SupportedPictureSizes;
                    //					foreach(Android.Hardware.Camera.Size aa in ss)
                    //					{
                    //						Console.WriteLine(aa.Height +"," + aa.Width);
                    //					}
                }
                catch (Exception e)
                {
                    e.ToString();
                }
            };

            btn.SetOnTouchListener(this);
            enrollbtn.SetOnTouchListener(this);
            kechenbtn.SetOnTouchListener(this);

            btn.LongClick += delegate {
                mCamera.AutoFocus(null);
                tv.Text     = lessons[nowLessonNum].attendance[todayNum].attend.Count + "";
                result.Text = lessons[nowLessonNum].attendance[todayNum].late.Count + "";
                //hdler.PostDelayed (this,DELAY_MILLIS);
            };

            enrollbtn.Click += delegate {
                EditText            editT       = new EditText(this);
                AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
                alertDialog.SetTitle("请输入学号后3位:");
                alertDialog.SetView(editT);
                alertDialog.SetPositiveButton("确认", delegate {
                    xuehao     = editT.Text;
                    tv.Text    = "学号为" + xuehao + ",开始录入指纹。。。";
                    isIdentify = false;
                });
                alertDialog.SetNegativeButton("取消", delegate {
                });
                alertDialog.Show();
            };

            kechenbtn.Click += delegate {
                View     base2        = View.Inflate(this, Resource.Layout.kecheng, null);
                Button   deletelesson = base2.FindViewById <Button>(Resource.Id.button3);
                Button   backbtn      = base2.FindViewById <Button>(Resource.Id.button1);
                Button   addbtn       = base2.FindViewById <Button>(Resource.Id.button2);
                ListView listLesson   = base2.FindViewById <ListView>(Resource.Id.listView1);

                //SimpleAdapter sAdapter = new SimpleAdapter(Application.Context,

                deletelesson.Click += delegate {
                };

                addbtn.Click += delegate {
                    EditText     editT    = new EditText(this);
                    EditText     edittime = new EditText(this);
                    LinearLayout ll       = new LinearLayout(this);
                    ll.Orientation = Orientation.Vertical;
                    ll.AddView(editT);
                    ll.AddView(edittime);
                    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
                    alertDialog.SetTitle("请输入课程名和时间:");
                    alertDialog.SetView(ll);
                    alertDialog.SetPositiveButton("确认", delegate {
                        //lessons.Add(editT.Text);
                        MyLesson myl = new MyLesson(editT.Text, Convert.ToDateTime(edittime.Text.Insert(2, ":")));
                        lessons.Add(myl);
                        adapter.Add(editT.Text);
                        adapter.NotifyDataSetChanged();
                        Console.WriteLine("添加课程...");
                        BinaryFormatter formatters = new BinaryFormatter();
                        using (Stream stream = File.Open(ImagePath + "lessons", FileMode.OpenOrCreate))
                            formatters.Serialize(stream, lessons);
                        tv.Text = "课程名为" + editT.Text + ",请录入指纹。。。";
                    });
                    alertDialog.SetNegativeButton("取消", delegate {
                    });
                    alertDialog.Show();
                };

                //返回
                backbtn.Click += delegate {
                    SetContentView(fl);
                };

                //如果开了自动,则关闭
                if (autoSw.Checked)
                {
                    hdler.RemoveCallbacks(this);
                    autoSw.Checked = false;
                }
                SetContentView(base2);
            };

            autoSw.CheckedChange += delegate {
                if (autoSw.Checked)
                {
                    hdler.PostDelayed(this, DELAY_MILLIS);
                }
                else
                {
                    hdler.RemoveCallbacks(this);
                }
            };


            //zoom放大
//			sk.ProgressChanged += delegate {
//				Android.Hardware.Camera.Parameters  p = mCamera.GetParameters();
//				int maxPa = p.MaxZoom;
//				int maxCa = sk.Max;
//				p.Zoom = maxPa * sk.Progress / maxCa;
//				mCamera.SetParameters(p);
//			};
        }