コード例 #1
0
        private void StartCapturing(IntPtr handle, CancellationToken ct)
        {
            var stop = false;

            while (!stop && !ct.IsCancellationRequested)
            {
                try
                {
                    var capture = CaptureWindow(handle);
                    OnImageCaptured?.Invoke(capture);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Capturing error: {e.Message}. Stopping capture and trying to find window again.");
                    stop = true;
                }
            }
        }
コード例 #2
0
        private void ImageCaptured(Bitmap bitmap)
        {
            DateTime dtCap = DateTime.Now;

            // Always save the bitmap
            lock ( _bitmapLock )
            {
                _bitmap = bitmap;
            }

            // FPS affects the callbacks only
            if (_fpslimit != -1)
            {
                if (_dtLastCap != DateTime.MinValue)
                {
                    double milliseconds = ((dtCap.Ticks - _dtLastCap.Ticks) / TimeSpan.TicksPerMillisecond) * 1.15;
                    if (milliseconds + _timeBehind >= _timeBetweenFrames)
                    {
                        _timeBehind = (milliseconds - _timeBetweenFrames);
                        if (_timeBehind < 0.0)
                        {
                            _timeBehind = 0.0;
                        }
                    }
                    else
                    {
                        _timeBehind = 0.0;
                        return; // ignore the frame
                    }
                }
            }

            if (OnImageCaptured != null)
            {
                var fps = ( int )(1 / dtCap.Subtract(_dtLastCap).TotalSeconds);
                OnImageCaptured.Invoke(this, new CameraEventArgs(bitmap, fps));
            }

            _dtLastCap = dtCap;
        }
コード例 #3
0
 public void TakeCameraImage()
 {
     Dexter.WithContext(_context)
     .WithPermissions(Manifest.Permission.Camera, Manifest.Permission.WriteExternalStorage)
     .WithListener(new MultiplePermissionsListener((permissions, token) =>
     {
         token.ContinuePermissionRequest();
     }, (report) =>
     {
         if (report.AreAllPermissionsGranted())
         {
             fileName = GenerateRandomString(6) + ".jpg";
             Intent takePictureIntent = new Intent(MediaStore.ActionImageCapture);
             takePictureIntent.PutExtra(MediaStore.ExtraOutput, GetCacheImagePath(fileName));
             if (takePictureIntent.ResolveActivity(_context.PackageManager) != null)
             {
                 OnImageCaptured?.Invoke(this, new ImageSelectedEventArgs {
                     imageIntent = takePictureIntent, fileName = fileName
                 });
             }
         }
     })).Check();
 }