예제 #1
0
    ///////////////////////////////////////////////////////////////////////////////
    // Defining Constants                                                        //
    ///////////////////////////////////////////////////////////////////////////////
    #region CONSTANTS
    #endregion //CONSTANTS

    ///////////////////////////////////////////////////////////////////////////////
    // Defining Variables, Enumerations, Events                                  //
    ///////////////////////////////////////////////////////////////////////////////
    #region FIELDS
    #endregion //FIELDS

    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////
    #region CONSTRUCTION

    /// <summary>
    /// Initializes a new instance of the ScreenCaptureProperties class.
    /// </summary>
    /// <param name="newVideoInputDevice">The friendly name of the video input device to use.</param>
    /// <param name="newAudioInputDevice">The friendly name of the audio input device to use.</param>
    /// <param name="newVideoCompressor">The friendly name of the video compressor to use.</param>
    /// <param name="newAudioCompressor">The friendly name of the audio compressor to use.</param>
    /// <param name="newFrameRate">The frame rate for the video stream.</param>
    /// <param name="newVideoSize">The size of the video stream.</param>
    /// <param name="newFilename">The filename for the video recording.</param>
    /// <param name="newCaptureMode">The <see cref="CaptureMode"/> flags for the recording.</param>
    /// <param name="newMonitorIndex">The zero-based index of the monitor whichs surface
    /// should be captured.</param>
    /// <param name="newPreviewWindow">The <see cref="Control"/> on which the preview
    /// stream of the DirectShow graph should be shown.</param>
    public ScreenCaptureProperties(
      string newVideoInputDevice,
      string newAudioInputDevice,
      string newVideoCompressor,
      string newAudioCompressor,
      int newFrameRate,
      Size newVideoSize,
      string newFilename,
      CaptureMode newCaptureMode,
      int newMonitorIndex,
      Control newPreviewWindow)
      : base(
      newVideoInputDevice,
      newAudioInputDevice,
      newVideoCompressor,
      newAudioCompressor,
      newFrameRate,
      newVideoSize,
      newFilename,
      newCaptureMode,
      newPreviewWindow)
    {
      this.PreviewWindow = newPreviewWindow;
      this.MonitorIndex = newMonitorIndex;
    }
예제 #2
0
		public bool Capture(Contact contact, IInputElement element, CaptureMode captureMode)
		{
			if(element == null)
				captureMode = CaptureMode.None;
			if(captureMode == CaptureMode.None)
				element = null;

			DependencyObject oldCaptured = contact.InputArgs.Captured;
			if(oldCaptured == element)
				return true;

			using (dispatcher.DisableProcessing())
			{
				long timestamp = Stopwatch.GetTimestamp();
				if (contact.InputArgs.Captured != null)
					RaiseCaptureEvent(contact, MultitouchScreen.LostContactCaptureEvent, contact.InputArgs.Captured, timestamp);


				contact.InputArgs.Captured = (DependencyObject)element;
				contact.InputArgs.CaptureState = captureMode;

				if (contact.InputArgs.Captured != null)
					RaiseCaptureEvent(contact, MultitouchScreen.GotContactCaptureEvent, contact.InputArgs.Captured, timestamp);
			}
			return true;
		}
예제 #3
0
        public static bool Capture(UIElement element, CaptureMode mode)
        {
            if (mode != CaptureMode.None)
            {
                if (element == null)
                {
                    throw new ArgumentException();
                }

                /// Make sure the element is attached
                /// to the MainWindow subtree.
                if (!IsMainWindowChild(element))
                {
                    throw new ArgumentException();
                }

                if (mode == CaptureMode.SubTree)
                {
                    throw new NotImplementedException();
                }

                if (mode == CaptureMode.Element)
                {
                    _captureElement = element;
                }
            }
            else
            {
                _captureElement = null;
            }

            return true;
        }
        public FPScanner(DeviceIdentity deviceIdentity, int index, CaptureMode captureMode = CaptureMode.PREVIEW_IMAGE_AUTO_DETECT, NativeInterfaceVersion nativeInterfaceVersion = NativeInterfaceVersion.VC3v2)
        {
            this.DeviceIdentity         = deviceIdentity;
            this.captureMode            = captureMode;
            this.nativeInterfaceVersion = nativeInterfaceVersion;

            worker.DoWork += worker_DoWork;

            InitScanner(index);

            this.Encoder = new Dermalog.Afis.FingerCode3.Encoder();
        }
예제 #5
0
        private Image CaptureWindow(CaptureMode mode)
        {
            Image     img     = null;
            IntPtr    handle  = IntPtr.Zero;
            Rectangle monitor = Rectangle.Empty;

            switch (mode)
            {
            case CaptureMode.FullScreen:
                handle = WindowNative.GetDesktopWindow();
                if (CaptureSetting.FullScreenMode == FullScreenMode.MainMonitor)
                {
                    monitor = Screen.PrimaryScreen.Bounds;
                }
                else if (CaptureSetting.FullScreenMode == FullScreenMode.ActiveMonitor)
                {
                    monitor = Screen.GetBounds(Cursor.Position);
                }
                else if (CaptureSetting.FullScreenMode == FullScreenMode.AllMonitor)
                {
                    monitor = SystemInformation.VirtualScreen;
                }
                img = CaptureWindow(handle, monitor.X, monitor.Y, monitor.Width, monitor.Height);
                break;

            case CaptureMode.ActiveProcess:
                handle = WindowNative.GetForegroundWindow();
                img    = CaptureWindow(handle, 0, 0, 0, 0);
                break;

            case CaptureMode.Region:
                handle  = WindowNative.GetDesktopWindow();
                monitor = SystemInformation.VirtualScreen;

                using (var tmp = CaptureWindow(handle, monitor.X, monitor.Y, monitor.Width, monitor.Height))
                    using (var dialog = new CaptureBackgroundDialog(tmp))
                    {
                        dialog.TopMost = true;
                        dialog.BringToFront();
                        if (dialog.ShowDialog() != DialogResult.OK)
                        {
                            return(null);
                        }

                        img = dialog.Image;
                    }
                break;

            default: return(null);
            }
            return(img);
        }
예제 #6
0
        public SolidColorBrush LoadAverageColor(CaptureMode captureMode, ScreenDisplayItem screen = null)
        {
            var img        = LoadBitmap(captureMode, screen);
            var background = GetDominantColor(img);

            Debug.Print(background.ToString());
            var brush = new SolidColorBrush(background)
            {
                Brightness = 1f
            };

            return(brush);
        }
예제 #7
0
        void OnApplicationPause(bool pause)
        {
            if (pause)
            {
                // require privledges to be checked again.
                _canCapture  = false;
                _captureMode = CaptureMode.Inactive;

                if (_playbackStarted)
                {
                    StopCapture();
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Captures the mouse within the specified input element.
        /// </summary>
        /// <param name="view">The view for which to set mouse capture.</param>
        /// <param name="element">The element to capture the mouse.</param>
        /// <param name="mode">The mouse capture mode.</param>
        /// <returns><c>true</c> if the mouse was successfully captured; otherwise, <c>false</c>.</returns>
        public static Boolean Capture(PresentationFoundationView view, IInputElement element, CaptureMode mode)
        {
            Contract.Require(view, "view");

            if (element != null)
            {
                return view.CaptureMouse(element, mode);
            }
            else
            {
                view.ReleaseMouse();
                return true;
            }
        }
예제 #9
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            //PhotoCamera cam = new Microsoft.Devices.PhotoCamera();
            //viewfinderBrush.SetSource(cam);

            selectphoto = new PhotoChooserTask();
            selectphoto.Completed += new EventHandler<PhotoResult>(selectphoto_Completed);

            //canvas1.Visibility = Visibility.Visible;
            GuidelineIn.Begin();
            cm = CaptureMode.CaptureFrame;
        }
예제 #10
0
        void CaptureWindow()
        {
            CaptureMode captureMode = CaptureMode.None;

            if (conf.CaptureWindowsInteractive)
            {
                captureMode = CaptureMode.Window;
            }
            else
            {
                captureMode = CaptureMode.ActiveWindow;
            }
            captureForm.MakeCapture(captureMode, true);
        }
예제 #11
0
        void OnApplicationPause(bool pause)
        {
            if (pause)
            {
                if (_isCapturing)
                {
                    // require privledges to be checked again.
                    _canCapture  = false;
                    _captureMode = CaptureMode.Inactive;

                    StopCapture();
                }
            }
        }
예제 #12
0
 private void checkBoxLoopback_CheckedChanged(object sender, EventArgs e)
 {
     if (checkBoxLoopback.Checked)
     {
         captureMode = CaptureMode.LoopbackCapture;
         RefreshDevices();
         this.TopMost = true;
     }
     else
     {
         captureMode = CaptureMode.Capture;
         RefreshDevices();
         this.TopMost = false;
     }
 }
        /// <summary>
        /// Begins tracking the specified touch.
        /// </summary>
        /// <param name="touchID">The unique identifier of the touch to start tracking.</param>
        /// <param name="captureElement">The element which is capturing the new touch.</param>
        /// <param name="captureMode">The capture mode for the new touch.</param>
        /// <returns><see langword="true"/> if tracking started successfully; otherwise, <see langword="false"/>.</returns>
        public Boolean StartTracking(Int64 touchID, IInputElement captureElement, CaptureMode captureMode)
        {
            if (active.ContainsKey(touchID))
            {
                return(false);
            }

            var tracker = pool.Retrieve();

            tracker.OnRetrieveFromPool(touchID, captureElement, captureMode);

            active.Add(touchID, tracker);
            tracker.Update();

            return(true);
        }
        public HoloLensCamera(CaptureMode captureMode, PixelFormat pixelFormat = PixelFormat.BGRA8)
        {
            desiredPixelFormat = pixelFormat;
            CameraType         = CameraType.Invalid;
            CaptureMode        = captureMode;

#if CAN_USE_UNITY_TYPES && UNITY_WSA && CAN_USE_UWP_TYPES
            IntPtr coordinateSystemPtr;
            // this must be done from the main thread, so done in
            coordinateSystemPtr = UnityEngine.XR.WSA.WorldManager.GetNativeISpatialCoordinateSystemPtr();
            if (coordinateSystemPtr != null)
            {
                rootCoordinateSystem = WinRTExtensions.GetSpatialCoordinateSystem(coordinateSystemPtr);
            }
#endif
        }
예제 #15
0
        public static void RecordTo(string fileName, TimeSpan time, WaveFormat format)
        {
            CaptureMode captureMode = CaptureMode.Capture;
            DataFlow    dataFlow    = captureMode == CaptureMode.Capture ? DataFlow.Capture : DataFlow.Render;

            var devices = MMDeviceEnumerator.EnumerateDevices(dataFlow, DeviceState.Active);
            var device  = devices.FirstOrDefault();

            using (WasapiCapture soundIn = captureMode == CaptureMode.Capture
                ? new WasapiCapture()
                : new WasapiLoopbackCapture())
            {
                soundIn.Device = device;
                soundIn.Initialize();
                SoundInSource soundInSource = new SoundInSource(soundIn)
                {
                    FillWithZeros = false
                };
                IWaveSource convertedSource = soundInSource
                                              .ChangeSampleRate(format.SampleRate) // sample rate
                                              .ToSampleSource()
                                              .ToWaveSource(format.BitsPerSample); //bits per sample
                using (convertedSource = format.Channels == 1 ? convertedSource.ToMono() : convertedSource.ToStereo())
                {
                    using (WaveWriter waveWriter = new WaveWriter(fileName, convertedSource.WaveFormat))
                    {
                        soundInSource.DataAvailable += (s, e) =>
                        {
                            byte[] buffer = new byte[convertedSource.WaveFormat.BytesPerSecond / 2];
                            int    read;
                            while ((read = convertedSource.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                waveWriter.Write(buffer, 0, read);
                            }
                        };

                        soundIn.Start();

                        Console.WriteLine("Started recording");
                        Thread.Sleep(time);

                        soundIn.Stop();
                        Console.WriteLine("Finished recording");
                    }
                }
            }
        }
예제 #16
0
        void CaptureFormKeyDown(object sender, KeyEventArgs e)
        {
            // Check fixmode
            if (e.KeyCode == Keys.ShiftKey)
            {
                if (fixMode == FixMode.None)
                {
                    fixMode = FixMode.Initiated;
                    return;
                }
            }
            if (e.KeyCode == Keys.Escape)
            {
                DialogResult = DialogResult.Cancel;
            }
            else if (e.KeyCode == Keys.M)
            {
                // Toggle mouse cursor
                capture.CursorVisible = !capture.CursorVisible;
                pictureBox.Invalidate();
            }
            else if (e.KeyCode == Keys.V && conf.isExperimentalFeatureEnabled("Video"))
            {
                capture.CaptureDetails.CaptureMode = CaptureMode.Video;
                pictureBox.Invalidate();
            }
            else if (e.KeyCode == Keys.Space)
            {
                switch (captureMode)
                {
                case CaptureMode.Region:
                    captureMode = CaptureMode.Window;
                    break;

                case CaptureMode.Window:
                    captureMode = CaptureMode.Region;
                    break;
                }
                pictureBox.Invalidate();
                selectedCaptureWindow = null;
                PictureBoxMouseMove(this, new MouseEventArgs(MouseButtons.None, 0, Cursor.Position.X, Cursor.Position.Y, 0));
            }
            else if (e.KeyCode == Keys.Return && captureMode == CaptureMode.Window)
            {
                DialogResult = DialogResult.OK;
            }
        }
예제 #17
0
        public static void Capture(CaptureMode screenCaptureMode = CaptureMode.Screen, string nameProcess = "", int L = 0, int T = 0, int R = 0, int B = 0)
        {
            Rectangle bounds;

            if (L != 0 || T != 0 || R != 0 || B != 0)
            {
                bounds = new Rectangle(L, T, R, B);
            }
            else
            {
                var handle = GetForegroundWindow();
                var rect   = new Rect();
                GetWindowRect(handle, ref rect);

                bounds = new Rectangle(rect.Left, rect.Top, rect.Right, rect.Bottom);
            }
            try
            {
                if (screenCaptureMode == CaptureMode.Screen)
                {
                    var result = new Bitmap(bounds.Width, bounds.Height);

                    using (var g = Graphics.FromImage(result))
                    {
                        g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);

                        //Graphics.FromHwnd
                    }

                    bit = result;
                }
                else
                {
                    System.Diagnostics.Process[] mass = System.Diagnostics.Process.GetProcessesByName(nameProcess);
                    IntPtr   it = mass[0].MainWindowHandle;
                    Graphics gr = Graphics.FromHwnd(it);
                    bit = new Bitmap(bounds.Width, bounds.Height);
                    gr.DrawImage(bit, new Point(0, 0));

                    //CursorPosition = new Point(Cursor.Position.X - rect.Left, Cursor.Position.Y - rect.Top);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #18
0
        private void ChangeFormState()
        {
            switch (_currentCaptureMode)
            {
            case CaptureMode.Waiting:
                ux_btnCapture.Text  = "Stop Capture";
                _currentCaptureMode = CaptureMode.Capturing;
                BeginCapture();
                break;

            case CaptureMode.Capturing:
                ux_btnCapture.Text  = "Capture";
                _currentCaptureMode = CaptureMode.Waiting;
                EndCapture();
                break;
            }
        }
예제 #19
0
        public Form1()
        {
            InitializeComponent();

            pictureBox1.Visible           = false;
            saveAsButton.Enabled          = false;
            copyToolStripMenuItem.Visible = false;

            //default mode
            currentMode  = CaptureMode.PICTURE_STATIC;
            originalSize = this.Size;

            menuStrip1.BringToFront();

            //initialize the ControlsWindow for later use
            cw = new ControlsWindow(this.Location.X, this.Location.Y, this);
        }
예제 #20
0
        public RecordForm(CaptureMode mode)
        {
            InitializeComponent();

            DoubleBuffered = true;

            _minSize = new Size(80 + (LineSize * 2), 80 + (LineSize * 2) + HeaderSize);
            Mode     = mode;

            if (Mode == CaptureMode.RecordGif)
            {
                label_type.Text = "GIF";
            }
            else if (Mode == CaptureMode.RecordVideo)
            {
                label_type.Text = "VIDEO";
            }
        }
예제 #21
0
        private void HandleOnTriggerDown(byte controllerId, float triggerValue)
        {
            if (_canCapture)
            {
                _captureMode = (_captureMode == CaptureMode.Delayed) ? CaptureMode.Inactive : _captureMode + 1;

                // Stop & Start to clear the previous mode.
                if (_isCapturing)
                {
                    StopCapture();
                }

                if (_captureMode != CaptureMode.Inactive)
                {
                    StartMicrophone();
                }
            }
        }
예제 #22
0
        public CaptureForm(ICapture capture, List <WindowDetails> windows)
        {
            if (currentForm != null)
            {
                LOG.Debug("Found currentForm, Closing already opened CaptureForm");
                currentForm.Close();
                currentForm = null;
                Application.DoEvents();
            }
            currentForm = this;

            // clean up
            this.FormClosed += delegate {
                currentForm = null;
                LOG.Debug("Remove CaptureForm from currentForm");
            };

            this.capture = capture;
            this.windows = windows;
            captureMode  = capture.CaptureDetails.CaptureMode;

            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            this.Text = "Greenshot capture form";

            // Make sure we never capture the captureform
            WindowDetails.RegisterIgnoreHandle(this.Handle);
            // TODO: Need to call unregister at close

            // set cursor location
            cursorPos = WindowCapture.GetCursorLocation();
            // Offset to screen coordinates
            cursorPos.Offset(-capture.ScreenBounds.X, -capture.ScreenBounds.Y);

            this.SuspendLayout();
            pictureBox.Image = capture.Image;
            this.Bounds      = capture.ScreenBounds;
            this.ResumeLayout();

            // Fix missing focus
            WindowDetails.ToForeground(this.Handle);
        }
예제 #23
0
        public Image GetImage(CaptureMode captureMode)
        {
            IntPtr intPtr = WinApi.FindWindow(null, this.Name);
            Image  image  = null;

            if (captureMode == CaptureMode.DirectX)
            {
                image = Direct3DCapture.CaptureWindow(intPtr);
            }
            else
            {
                if (captureMode != CaptureMode.Gdi)
                {
                    throw new NotImplementedException("尚未實作的擷取畫面模式");
                }
                image = (new ScreenCapture()).CaptureWindow(intPtr);
            }
            return(image);
        }
예제 #24
0
        public void DetachInput()
        {
            if (HasInputFocus)
            {
                _mouseCaptured    = null;
                _mouseCaptureMode = CaptureMode.None;

                InputManager inputManager = InputManager.Instance;
                inputManager.KeyPreview            -= HandleKeyPreview;
                inputManager.KeyPressed            -= HandleKeyPress;
                inputManager.TouchDown             -= HandleTouchDown;
                inputManager.TouchUp               -= HandleTouchUp;
                inputManager.TouchMove             -= HandleTouchMove;
                inputManager.RoutedInputEventFired -= HandleRoutedInputEvent;
                inputManager.Deactivated           -= HandleDeactivated;
                HasInputFocus = false;
                RemoveCurrentFocus();
            }
        }
예제 #25
0
        /**
         * Use this for initialization.
         */
        private void Start()
        {
            // Variable initialization
            this.CurrentMode   = CaptureMode.None;
            this.NextMode      = CaptureMode.None;
            this.isSwitching   = false;
            this.disposeAction = null;

            // Get reference to other scripts in the scene
            this.logger = DebugLogger.Instance;

            // Deactivate this script if necessary components are missing
            if ((this.logger == null) || (this.PhotoCapture == null) || (this.VideoCapture == null))
            {
                Debug.LogError("CaptureManager: Script references not set properly.");
                this.enabled = false;
                return;
            }
        }
        /// <summary>
        /// Capturesall cursors in the collection.
        /// </summary>
        /// <returns><see langword="true"/> if all cursors were captured; otherwise, <see langword="false"/>.</returns>
        public Boolean CaptureAll(IInputElement element, CaptureMode mode)
        {
            if (active.Count == 0)
            {
                return(false);
            }

            var failed = false;

            foreach (var kvp in active)
            {
                if (!kvp.Value.Capture(element, mode))
                {
                    failed = true;
                }
            }

            return(!failed);
        }
예제 #27
0
        public RegionCapture()
        {
            this.m_CaptureMode = CaptureMode.RegionSelect;

            this.WindowState     = FormWindowState.Maximized;
            this.FormBorderStyle = FormBorderStyle.None;
            this.DoubleBuffered  = true;
            this.Opacity         = 0.75f;
            this.TransparencyKey = Color.White;
            m_OriginalBackColor  = this.BackColor;            //Cache first BG Color before setting a new value;
            this.BackColor       = Color.White;



            this.Load      += RegionCapture_Load;
            this.MouseDown += RegionCapture_MouseDown;
            this.MouseMove += RegionCapture_MouseMove;
            this.MouseUp   += RegionCapture_MouseUp;
            this.KeyUp     += RegionCapture_KeyUp;
        }
예제 #28
0
        public RecorderWindown(CaptureMode mode, string video_path, string video_name, string video_type, int video_framerate, int video_bitrate, string capture_path, string capture_type, Window mainwindown)
        {
            InitializeComponent();
            this.video_path        = video_path;
            this.video_name        = video_name;
            this.video_type        = video_type;
            this.video_framerate   = video_framerate;
            this.video_bitrate     = video_bitrate;
            this.capture_path      = capture_path;
            this.capture_type      = capture_type;
            this.mainwindown       = mainwindown;
            SizeButtom             = 20;
            MINWIDTH               = MINHEIGHT = 100;
            region.MinHeight       = MINHEIGHT;
            region.MinWidth        = MINWIDTH;
            border.StrokeDashArray = new DoubleCollection()
            {
                4, 3
            };
            MAXWIDTH               = System.Windows.SystemParameters.PrimaryScreenWidth;
            MAXHEIGHT              = System.Windows.SystemParameters.PrimaryScreenHeight;
            EventCanvas            = new Canvas();
            EventCanvas.MouseDown += eventcanvas_down;
            EventCanvas.MouseUp   += eventcanvas_up;
            EventCanvas.MouseMove += eventcanvas_move;
            fullregion.Children.Add(EventCanvas);
            Canvas.SetLeft(toolbar, MAXWIDTH - 40);
            switch (mode)
            {
            case CaptureMode.Fullscreen:
                FullScreen();
                break;

            case CaptureMode.SelectRegion:
                SelectRegion();
                break;

            case CaptureMode.AroundMouse:
                break;
            }
        }
예제 #29
0
        /// <summary>
        /// Captures or releases the mouse capture.
        /// </summary>
        /// <param name="element">Element to capture mouse for or <c>null</c> to release mouse capture.</param>
        /// <param name="captureMode">Capture mode.</param>
        /// <returns>Returns true if the capture or release was successful.</returns>
        public bool CaptureMouse(UIElement element, CaptureMode captureMode)
        {
            if (element == null)
            {
                captureMode = CaptureMode.None;
            }
            if (captureMode == CaptureMode.None)
            {
                element = null;
            }

            if (element != null && (!element.IsVisible || !element.IsEnabled))
            {
                return(false);
            }

            _mouseCaptured    = element;
            _mouseCaptureMode = captureMode;

            return(true);
        }
예제 #30
0
        private void HandleOnButtonDown(byte controllerId, MLInputControllerButton button)
        {
            if (_controllerConnectionHandler.IsControllerValid(controllerId))
            {
                if (_canCapture && button == MLInputControllerButton.Bumper)
                {
                    _captureMode = (_captureMode == CaptureMode.Delayed) ? CaptureMode.Inactive : _captureMode + 1;

                    // Stop & Start to clear the previous mode.
                    if (_isCapturing)
                    {
                        StopCapture();
                    }

                    if (_captureMode != CaptureMode.Inactive)
                    {
                        StartCapture();
                    }
                }
            }
        }
예제 #31
0
 /// <summary>
 /// Initializes a new instance of the CaptureDeviceProperties class.
 /// </summary>
 /// <param name="newVideoInputDevice">The <see cref="CameraInfo"/> with the video input device to use.</param>
 /// <param name="newAudioInputDevice">The friendly name of the audio input device to use.</param>
 /// <param name="newVideoCompressor">The friendly name of the video compressor to use.</param>
 /// <param name="newAudioCompressor">The friendly name of the audio compressor to use.</param>
 /// <param name="newFrameRate">The frame rate for the video stream.</param>
 /// <param name="newVideoSize">The size of the video stream.</param>
 /// <param name="newFilename">The filename for the video recording.</param>
 /// <param name="newCaptureMode">The <see cref="CaptureMode"/> flags for the recording.</param>
 /// <param name="newPreviewWindow">The <see cref="Control"/> where the preview
 /// should be shown or null, if no preview should be shown.</param>
 public CaptureDeviceProperties(
     CameraInfo newVideoInputDevice,
     string newAudioInputDevice,
     string newVideoCompressor,
     string newAudioCompressor,
     int newFrameRate,
     Size newVideoSize,
     string newFilename,
     CaptureMode newCaptureMode,
     Control newPreviewWindow)
 {
     this.videoInputDevice = newVideoInputDevice;
     this.videoCompressor  = newVideoCompressor;
     this.audioInputDevice = newAudioInputDevice;
     this.audioCompressor  = newAudioCompressor;
     this.frameRate        = newFrameRate;
     this.videoSize        = newVideoSize;
     this.filename         = newFilename;
     this.captureMode      = newCaptureMode;
     this.previewWindow    = newPreviewWindow;
 }
예제 #32
0
 // Use this for initialization
 void Start()
 {
     try
     {
         bufTex = new Texture2D(renderTex.width, renderTex.height, WorldManager.Inst.textureFormat, false);
         //try to initialize hardware camera
         WebCamDevice[] devices = WebCamTexture.devices;
         string         camName = "";
         if (devices.Length > 0)
         {
             camName = devices[0].name;
         }
         //use back facing camera if it exists
         for (int i = 0; i < devices.Length; i++)
         {
             Debug.Log("Device:" + devices[i].name + "IS FRONT FACING:" + devices[i].isFrontFacing);
             if (!devices[i].isFrontFacing)
             {
                 camName = devices[i].name;
             }
         }
         if (camName != "")
         {
             webCamTex = new WebCamTexture(camName, 1024, 768);
             webCamTex.Play();
             captureMode = CaptureMode.camera;
             webcamDisplay.sharedMaterial.mainTexture = webCamTex;
             dummyObject.SetActive(false);
         }
         else
         {
             Debug.Log("Camera not found!");
             captureMode = CaptureMode.render;
         }
     }
     finally
     {
     }
 }
예제 #33
0
        // Create a File for saving an image or video */
        public static File GetOutputMediaFile(CaptureMode captureMode)
        {
            // To be safe, you should check that the SDCard is mounted
            // using Environment.getExternalStorageState() before doing this.

            File mediaStorageDir = new File(Android.OS.Environment.GetExternalStoragePublicDirectory(
                                                Android.OS.Environment.DirectoryPictures), "WeClip");

            //// This location works best if you want the created images to be shared
            //// between applications and persist after your app has been uninstalled.

            // Create the storage directory if it does not exist
            if (!mediaStorageDir.Exists())
            {
                if (!mediaStorageDir.Mkdirs())
                {
                    Log.Debug("CameraFileSave", "Failed to create directory.");
                    return(null);
                }
            }

            string timeStamp = new Java.Text.SimpleDateFormat("yyyyMMdd_HHmmss").Format(new Java.Util.Date());
            File   mediaFile;

            if (captureMode == CaptureMode.Photo)
            {
                mediaFile = new File(mediaStorageDir.Path + File.Separator + "IMG_" + timeStamp + ".jpg");
            }
            else if (captureMode == CaptureMode.Video)
            {
                mediaFile = new File(mediaStorageDir.Path + File.Separator + "VID_" + timeStamp + ".mp4");
            }
            else
            {
                return(null);
            }

            return(mediaFile);
        }
예제 #34
0
        /// <summary>
        /// Captures the screenshot and readies for rendering
        /// </summary>
        public void Capture(CaptureMode CapMode)
        {
            // ready states
            CanDraw = false;
            Alpha   = 0;

            switch (CapMode)
            {
            case CaptureMode.Clipboard:
                //CaptureFromBitBlt();
                CaptureFromClipboard();
                break;

            case CaptureMode.BitBlt:
                CaptureFromBitBlt();
                break;

            default:
                CaptureFromClipboard();
                break;
            }
        }
        /// <summary>
        /// Captures the cursor to the specified element.
        /// </summary>
        /// <param name="element">The element to which to assign capture.</param>
        /// <param name="mode">The capture mode to apply.</param>
        /// <returns><see langword="true"/> if the cursor was captured; otherwise, <see langword="false"/>.</returns>
        public Boolean Capture(IInputElement element, CaptureMode mode)
        {
            if ((element != null && mode == CaptureMode.None) || (element == null && mode != CaptureMode.None))
            {
                throw new ArgumentException(nameof(mode));
            }

            if (withCapture == element)
            {
                return(true);
            }

            if (!(element?.IsValidForInput() ?? false))
            {
                return(false);
            }

            if (withCapture != null)
            {
                Release();
            }

            withCapture = element;
            captureMode = mode;

            var uiElement = withCapture as UIElement;

            if (uiElement != null)
            {
                SetIsCaptured(uiElement, true);

                UpdateIsCaptureWithin(uiElement, true);
                UpdateIsOver(uiElement);

                RaiseGotCapture(uiElement);
            }

            return(true);
        }
예제 #36
0
        public CaptureForm(ICapture capture, List<WindowDetails> windows)
        {
            if (currentForm != null) {
                LOG.Debug("Found currentForm, Closing already opened CaptureForm");
                currentForm.Close();
                currentForm = null;
                Application.DoEvents();
            }
            currentForm = this;

            // clean up
            this.FormClosed += delegate {
                currentForm = null;
                LOG.Debug("Remove CaptureForm from currentForm");
            };

            this.capture = capture;
            this.windows = windows;
            captureMode = capture.CaptureDetails.CaptureMode;

            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            this.Text = "Greenshot capture form";

            // Make sure we never capture the captureform
            WindowDetails.RegisterIgnoreHandle(this.Handle);
            // TODO: Need to call unregister at close

            // set cursor location
            cursorPos = WindowCapture.GetCursorLocation();
            // Offset to screen coordinates
            cursorPos.Offset(-capture.ScreenBounds.X, -capture.ScreenBounds.Y);

            this.SuspendLayout();
            pictureBox.Image = capture.Image;
            this.Bounds = capture.ScreenBounds;
            this.ResumeLayout();

            // Fix missing focus
            WindowDetails.ToForeground(this.Handle);
        }
예제 #37
0
 void CaptureFormKeyDown(object sender, KeyEventArgs e)
 {
     // Check fixmode
     if (e.KeyCode == Keys.ShiftKey) {
         if (fixMode == FixMode.None) {
             fixMode = FixMode.Initiated;
             return;
         }
     }
     if (e.KeyCode == Keys.Escape) {
         DialogResult = DialogResult.Cancel;
     } else if (e.KeyCode == Keys.M) {
         // Toggle mouse cursor
         capture.CursorVisible = !capture.CursorVisible;
         pictureBox.Invalidate();
     } else if (e.KeyCode == Keys.V && conf.isExperimentalFeatureEnabled("Video")) {
         capture.CaptureDetails.CaptureMode = CaptureMode.Video;
         pictureBox.Invalidate();
     } else if (e.KeyCode == Keys.Space) {
         switch (captureMode) {
             case CaptureMode.Region:
                 captureMode = CaptureMode.Window;
                 break;
             case CaptureMode.Window:
                 captureMode = CaptureMode.Region;
                 break;
         }
         pictureBox.Invalidate();
         selectedCaptureWindow = null;
         PictureBoxMouseMove(this, new MouseEventArgs(MouseButtons.None, 0, Cursor.Position.X, Cursor.Position.Y, 0));
     } else if (e.KeyCode == Keys.Return && captureMode == CaptureMode.Window) {
         DialogResult = DialogResult.OK;
     }
 }
예제 #38
0
파일: Stylus.cs 프로젝트: JianwenSun/cc
 /////////////////////////////////////////////////////////////////////
 /// <summary>
 ///     Captures the stylus to a particular element.
 /// </summary>
 /// <param name="element">
 ///     The element to capture the stylus to.
 /// </param>
 /// <param name="captureMode">
 ///     The kind of capture to acquire.
 /// </param>
 public static bool Capture(IInputElement element, CaptureMode captureMode)
 {
     // The stylus code watches mouse capture changes and it will trigger us to
     // [....] up all the stylusdevice capture settings to be the same as the mouse.
     // So we just call Mouse.Capture() here to trigger this all to happen.
     return Mouse.Capture(element, captureMode);
 }
예제 #39
0
        /// <summary>
        /// Creates a new photo capture based on the <paramref name="captureMode"/> specified.
        /// </summary>
        /// <param name="captureMode">Capture mode to create photo capture for.</param>
        /// <returns>Photo capture created.</returns>
        /// <exception cref="InvalidOperationException"><paramref name="captureMode"/> is not supported.</exception>
        private IPhotoCapture CreatePhotoCapture(CaptureMode captureMode)
        {
            Tracing.Trace("PhotoCamera: Creating new capture {0}", captureMode);

            IPhotoCapture capture;

            switch (captureMode)
            {
                case CaptureMode.LowLag:
                    capture = new LowLagCapture(this.CameraController);
                    break;
                case CaptureMode.Variable:
                    // VPS may not be supported on the current device.
                    if (!this.CameraController.MediaCapture.VideoDeviceController.VariablePhotoSequenceController.Supported)
                    {
                        throw new NotSupportedException("VPS is not supported.");
                    }

                    capture = new VariablePhotoCapture(this.CameraController);
                    break;
                default:
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Capture mode {0} is not supported.", captureMode));
            }

            this.captureStarted = false;
            this.SubscribeToCaptureEvents(capture);

            return capture;
        }
예제 #40
0
 public CaptureHelper(CaptureMode captureMode)
 {
     _captureMode = captureMode;
     _capture = new Capture();
 }
예제 #41
0
        private void shutterButton_Click(object sender, RoutedEventArgs e)
        {
            if (cm == CaptureMode.PostView)
            {
                lastView.Visibility = Visibility.Collapsed;
                //canvas1.Visibility = Visibility.Visible;
                GuidelineIn.Begin();
                cm = CaptureMode.CaptureFrame;
                return;
            }

            if (cam != null)
            {
                try
                {
                    // Start image capture.
                    cam.CaptureImage();

                    Stream stream = TitleContainer.OpenStream("Sounds/camera-click-1.wav");
                    SoundEffect effect = SoundEffect.FromStream(stream);
                    FrameworkDispatcher.Update();
                    effect.Play();
                }
                catch (Exception ex)
                {
                    this.Dispatcher.BeginInvoke(delegate()
                    {
                        // Cannot capture an image until the previous capture has completed.
                        txtDebug.Text = ex.Message;
                    });
                }
            }

            Console.Write("------------------- debug -------------------\n");
            PictureCollection pictures = library.Pictures;

            foreach (Picture pict in pictures)
            {
                Debug.WriteLine(String.Format("{0}\t{1}\t{2}", pict.Name, pict.Album.Name, pict.Date));
            }
        }
예제 #42
0
        // Cancel the focus if the half button press is released using the hardware shutter button.
        private void OnButtonRelease(object sender, EventArgs e)
        {
            Debug.WriteLine("OnButtonRelease");

            if (cm == CaptureMode.PostView)
            {
                lastView.Visibility = Visibility.Collapsed;
                //canvas1.Visibility = Visibility.Visible;
                GuidelineIn.Begin();
                cm = CaptureMode.CaptureFrame;
                return;
            }

            if (cam != null)
            {
                cam.CancelFocus();
            }
        }
예제 #43
0
        // Provide auto-focus with a half button press using the hardware shutter button.
        private void OnButtonHalfPress(object sender, EventArgs e)
        {
            Debug.WriteLine("OnButtonHalfPress");

            if (cm == CaptureMode.PostView)
            {
                lastView.Visibility = Visibility.Collapsed;
                //canvas1.Visibility = Visibility.Visible;
                GuidelineIn.Begin();
                cm = CaptureMode.CaptureFrame;
                return;
            }

            if (cam != null)
            {
                // Focus when a capture is not in progress.
                try
                {
                    this.Dispatcher.BeginInvoke(delegate()
                    {
                        txtDebug.Text = "Half Button Press: Auto Focus";
                    });

                    cam.Focus();
                }
                catch (Exception focusError)
                {
                    // Cannot focus when a capture is in progress.
                    this.Dispatcher.BeginInvoke(delegate()
                    {
                        txtDebug.Text = focusError.Message;
                    });
                }
            }
        }
예제 #44
0
        // Capture the image with a full button press using the hardware shutter button.
        private void OnButtonFullPress(object sender, EventArgs e)
        {
            Debug.WriteLine("OnButtonFullPress");

            if (cm == CaptureMode.PostView)
            {
                lastView.Visibility = Visibility.Collapsed;
                //canvas1.Visibility = Visibility.Visible;
                GuidelineIn.Begin();
                cm = CaptureMode.CaptureFrame;
                return;
            }

            if (cam != null)
            {
                try
                {
                    cam.CaptureImage();

                    Stream stream = TitleContainer.OpenStream("Sounds/camera-click-1.wav");
                    SoundEffect effect = SoundEffect.FromStream(stream);
                    FrameworkDispatcher.Update();
                    effect.Play();
                }
                catch (Exception ex)
                {
                    txtDebug.Text = ex.Message;
                    Debug.WriteLine("Error, {0}", ex.Message);
                }
            }
        }
예제 #45
0
 public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor, ScreenCaptureMode screenCaptureMode)
     : this(captureMode)
 {
     _captureMouseCursor = captureMouseCursor;
     _screenCaptureMode = screenCaptureMode;
 }
예제 #46
0
        /// <summary>
        /// Initializes a new photo capture controller, if needed.
        /// </summary>
        /// <param name="captureMode">Photo capture mode.</param>
        /// <param name="parameters">Camera capture parameters.</param>
        /// <returns>Awaitable task.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="parameters"/> is <see langword="null"/>.</exception>
        /// <exception cref="NotImplementedException"><paramref name="captureMode"/> is not supported.</exception>
        public async Task InitializePhotoCaptureAsync(CaptureMode captureMode, CaptureParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (parameters.ImageEncoding == null)
            {
                throw new ArgumentNullException("parameters", "Image encoding is not set.");
            }

            Tracing.Trace("PhotoCamera::InitializePhotoCaptureAsync");

            if (this.photoCapture != null && this.CaptureMode == captureMode && parameters.Equals(this.CaptureParameters))
            {
                Tracing.Trace("PhotoCamera: Capture is already initialized with the same parameters.");
                return;
            }

            this.CaptureMode       = captureMode;
            this.CaptureParameters = parameters;

            await this.DestroyPhotoCaptureAsync();

            this.photoCapture = this.CreatePhotoCapture(captureMode);

            await this.TaskEngine.EnqueueTaskAsync(new InitializePhotoCaptureTask(this.CameraController, this.photoCapture, parameters));
        }
예제 #47
0
        /// <summary>
        /// Make Capture with specified destinations
        /// </summary>
        private void MakeCapture()
        {
            Thread retrieveWindowDetailsThread = null;

            // This fixes a problem when a balloon is still visible and a capture needs to be taken
            // forcefully removes the balloon!
            if (!conf.HideTrayicon) {
                MainForm.Instance.NotifyIcon.Visible = false;
                MainForm.Instance.NotifyIcon.Visible = true;
            }
            LOG.Debug(String.Format("Capturing with mode {0} and using Cursor {1}", _captureMode, _captureMouseCursor));
            _capture.CaptureDetails.CaptureMode = _captureMode;

            // Get the windows details in a seperate thread, only for those captures that have a Feedback
            // As currently the "elements" aren't used, we don't need them yet
            switch (_captureMode) {
                case CaptureMode.Region:
                    // Check if a region is pre-supplied!
                    if (Rectangle.Empty.Equals(_captureRect)) {
                        retrieveWindowDetailsThread = PrepareForCaptureWithFeedback();
                    }
                    break;
                case CaptureMode.Window:
                    retrieveWindowDetailsThread = PrepareForCaptureWithFeedback();
                    break;
            }

            // Add destinations if no-one passed a handler
            if (_capture.CaptureDetails.CaptureDestinations == null || _capture.CaptureDetails.CaptureDestinations.Count == 0) {
                AddConfiguredDestination();
            }

            // Delay for the Context menu
            if (conf.CaptureDelay > 0) {
                Thread.Sleep(conf.CaptureDelay);
            } else {
                conf.CaptureDelay = 0;
            }

            // Capture Mousecursor if we are not loading from file or clipboard, only show when needed
            if (_captureMode != CaptureMode.File && _captureMode != CaptureMode.Clipboard) {
                _capture = WindowCapture.CaptureCursor(_capture);
                if (_captureMouseCursor) {
                    _capture.CursorVisible = conf.CaptureMousepointer;
                } else {
                    _capture.CursorVisible = false;
                }
            }

            switch(_captureMode) {
                case CaptureMode.Window:
                    _capture = WindowCapture.CaptureScreen(_capture);
                    _capture.CaptureDetails.AddMetaData("source", "Screen");
                    SetDPI();
                    CaptureWithFeedback();
                    break;
                case CaptureMode.ActiveWindow:
                    if (CaptureActiveWindow()) {
                        // Capture worked, offset mouse according to screen bounds and capture location
                        _capture.MoveMouseLocation(_capture.ScreenBounds.Location.X-_capture.Location.X, _capture.ScreenBounds.Location.Y-_capture.Location.Y);
                        _capture.CaptureDetails.AddMetaData("source", "Window");
                    } else {
                        _captureMode = CaptureMode.FullScreen;
                        _capture = WindowCapture.CaptureScreen(_capture);
                        _capture.CaptureDetails.AddMetaData("source", "Screen");
                        _capture.CaptureDetails.Title = "Screen";
                    }
                    SetDPI();
                    HandleCapture();
                    break;
                case CaptureMode.IE:
                    if (IECaptureHelper.CaptureIE(_capture, SelectedCaptureWindow) != null) {
                        _capture.CaptureDetails.AddMetaData("source", "Internet Explorer");
                        SetDPI();
                        HandleCapture();
                    }
                    break;
                case CaptureMode.FullScreen:
                    // Check how we need to capture the screen
                    bool captureTaken = false;
                    switch (_screenCaptureMode) {
                        case ScreenCaptureMode.Auto:
                            Point mouseLocation = User32.GetCursorLocation();
                            foreach (Screen screen in Screen.AllScreens) {
                                if (screen.Bounds.Contains(mouseLocation)) {
                                    _capture = WindowCapture.CaptureRectangle(_capture, screen.Bounds);
                                    captureTaken = true;
                                    break;
                                }
                            }
                            break;
                        case ScreenCaptureMode.Fixed:
                            if (conf.ScreenToCapture > 0 && conf.ScreenToCapture <= Screen.AllScreens.Length) {
                                _capture = WindowCapture.CaptureRectangle(_capture, Screen.AllScreens[conf.ScreenToCapture].Bounds);
                                captureTaken = true;
                            }
                            break;
                        case ScreenCaptureMode.FullScreen:
                            // Do nothing, we take the fullscreen capture automatically
                            break;
                    }
                    if (!captureTaken) {
                        _capture = WindowCapture.CaptureScreen(_capture);
                    }
                    SetDPI();
                    HandleCapture();
                    break;
                case CaptureMode.Clipboard:
                    Image clipboardImage = ClipboardHelper.GetImage();
                    if (clipboardImage != null) {
                        if (_capture != null) {
                            _capture.Image = clipboardImage;
                        } else {
                            _capture = new Capture(clipboardImage);
                        }
                        _capture.CaptureDetails.Title = "Clipboard";
                        _capture.CaptureDetails.AddMetaData("source", "Clipboard");
                        // Force Editor, keep picker
                        if (_capture.CaptureDetails.HasDestination(PickerDestination.DESIGNATION)) {
                            _capture.CaptureDetails.ClearDestinations();
                            _capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
                            _capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(PickerDestination.DESIGNATION));
                        } else {
                            _capture.CaptureDetails.ClearDestinations();
                            _capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
                        }
                        HandleCapture();
                    } else {
                        MessageBox.Show(Language.GetString("clipboard_noimage"));
                    }
                    break;
                case CaptureMode.File:
                    Image fileImage = null;
                    string filename = _capture.CaptureDetails.Filename;

                    if (!string.IsNullOrEmpty(filename)) {
                        try {
                            if (filename.ToLower().EndsWith("." + OutputFormat.greenshot)) {
                                ISurface surface = new Surface();
                                surface = ImageOutput.LoadGreenshotSurface(filename, surface);
                                surface.CaptureDetails = _capture.CaptureDetails;
                                DestinationHelper.GetDestination(EditorDestination.DESIGNATION).ExportCapture(true, surface, _capture.CaptureDetails);
                                break;
                            }
                        } catch (Exception e) {
                            LOG.Error(e.Message, e);
                            MessageBox.Show(Language.GetFormattedString(LangKey.error_openfile, filename));
                        }
                        try {
                            fileImage = ImageHelper.LoadImage(filename);
                        } catch (Exception e) {
                            LOG.Error(e.Message, e);
                            MessageBox.Show(Language.GetFormattedString(LangKey.error_openfile, filename));
                        }
                    }
                    if (fileImage != null) {
                        _capture.CaptureDetails.Title = Path.GetFileNameWithoutExtension(filename);
                        _capture.CaptureDetails.AddMetaData("file", filename);
                        _capture.CaptureDetails.AddMetaData("source", "file");
                        if (_capture != null) {
                            _capture.Image = fileImage;
                        } else {
                            _capture = new Capture(fileImage);
                        }
                        // Force Editor, keep picker, this is currently the only usefull destination
                        if (_capture.CaptureDetails.HasDestination(PickerDestination.DESIGNATION)) {
                            _capture.CaptureDetails.ClearDestinations();
                            _capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
                            _capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(PickerDestination.DESIGNATION));
                        } else {
                            _capture.CaptureDetails.ClearDestinations();
                            _capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
                        }
                        HandleCapture();
                    }
                    break;
                case CaptureMode.LastRegion:
                    if (!conf.LastCapturedRegion.IsEmpty) {
                        _capture = WindowCapture.CaptureRectangle(_capture, conf.LastCapturedRegion);
                        // TODO: Reactive / check if the elements code is activated
                        //if (windowDetailsThread != null) {
                        //	windowDetailsThread.Join();
                        //}

                        // Set capture title, fixing bug #3569703
                        foreach (WindowDetails window in WindowDetails.GetVisibleWindows()) {
                            Point estimatedLocation = new Point(conf.LastCapturedRegion.X + (conf.LastCapturedRegion.Width / 2), conf.LastCapturedRegion.Y + (conf.LastCapturedRegion.Height / 2));
                            if (window.Contains(estimatedLocation)) {
                                _selectedCaptureWindow = window;
                                _capture.CaptureDetails.Title = _selectedCaptureWindow.Text;
                                break;
                            }
                        }
                        // Move cursor, fixing bug #3569703
                        _capture.MoveMouseLocation(_capture.ScreenBounds.Location.X - _capture.Location.X, _capture.ScreenBounds.Location.Y - _capture.Location.Y);
                        //capture.MoveElements(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y);

                        _capture.CaptureDetails.AddMetaData("source", "screen");
                        SetDPI();
                        HandleCapture();
                    }
                    break;
                case CaptureMode.Region:
                    // Check if a region is pre-supplied!
                    if (Rectangle.Empty.Equals(_captureRect)) {
                        _capture = WindowCapture.CaptureScreen(_capture);
                        _capture.CaptureDetails.AddMetaData("source", "screen");
                        SetDPI();
                        CaptureWithFeedback();
                    } else {
                        _capture = WindowCapture.CaptureRectangle(_capture, _captureRect);
                        _capture.CaptureDetails.AddMetaData("source", "screen");
                        SetDPI();
                        HandleCapture();
                    }
                    break;
                default:
                    LOG.Warn("Unknown capture mode: " + _captureMode);
                    break;
            }
            // Wait for thread, otherwise we can't dipose the CaptureHelper
            if (retrieveWindowDetailsThread != null) {
                retrieveWindowDetailsThread.Join();
            }
            if (_capture != null) {
                LOG.Debug("Disposing capture");
                _capture.Dispose();
            }
        }
예제 #48
0
		/// <summary>
		/// Captures the specified element.
		/// </summary>
		/// <param name="element">The element.</param>
		/// <param name="captureMode">The capture mode.</param>
		/// <returns></returns>
		public bool Capture(IInputElement element, CaptureMode captureMode)
		{
			return MultitouchLogic.Current.ContactsManager.Capture(this, element, captureMode);
		}
예제 #49
0
        private void HandleCapture()
        {
            // Flag to see if the image was "exported" so the FileEditor doesn't
            // ask to save the file as long as nothing is done.
            bool outputMade = false;

            // Make sure the user sees that the capture is made
            if (_capture.CaptureDetails.CaptureMode == CaptureMode.File || _capture.CaptureDetails.CaptureMode == CaptureMode.Clipboard) {
                // Maybe not "made" but the original is still there... somehow
                outputMade = true;
            } else {
                // Make sure the resolution is set correctly!
                if (_capture.CaptureDetails != null && _capture.Image != null) {
                    ((Bitmap)_capture.Image).SetResolution(_capture.CaptureDetails.DpiX, _capture.CaptureDetails.DpiY);
                }
                DoCaptureFeedback();
            }

            LOG.Debug("A capture of: " + _capture.CaptureDetails.Title);

            // check if someone has passed a destination
            if (_capture.CaptureDetails.CaptureDestinations == null || _capture.CaptureDetails.CaptureDestinations.Count == 0) {
                AddConfiguredDestination();
            }

            // Create Surface with capture, this way elements can be added automatically (like the mouse cursor)
            Surface surface = new Surface(_capture);
            surface.Modified = !outputMade;

            // Register notify events if this is wanted
            if (conf.ShowTrayNotification && !conf.HideTrayicon) {
                surface.SurfaceMessage += SurfaceMessageReceived;

            }
            // Let the processors do their job
            foreach(IProcessor processor in ProcessorHelper.GetAllProcessors()) {
                if (processor.isActive) {
                    LOG.InfoFormat("Calling processor {0}", processor.Description);
                    processor.ProcessCapture(surface, _capture.CaptureDetails);
                }
            }

            // As the surfaces copies the reference to the image, make sure the image is not being disposed (a trick to save memory)
            _capture.Image = null;

            // Get CaptureDetails as we need it even after the capture is disposed
            ICaptureDetails captureDetails = _capture.CaptureDetails;
            bool canDisposeSurface = true;

            if (captureDetails.HasDestination(PickerDestination.DESIGNATION)) {
                DestinationHelper.ExportCapture(false, PickerDestination.DESIGNATION, surface, captureDetails);
                captureDetails.CaptureDestinations.Clear();
                canDisposeSurface = false;
            }

            // Disable capturing
            _captureMode = CaptureMode.None;
            // Dispose the capture, we don't need it anymore (the surface copied all information and we got the title (if any)).
            _capture.Dispose();
            _capture = null;

            int destinationCount = captureDetails.CaptureDestinations.Count;
            if (destinationCount > 0) {
                // Flag to detect if we need to create a temp file for the email
                // or use the file that was written
                foreach(IDestination destination in captureDetails.CaptureDestinations) {
                    if (PickerDestination.DESIGNATION.Equals(destination.Designation)) {
                        continue;
                    }
                    LOG.InfoFormat("Calling destination {0}", destination.Description);

                    ExportInformation exportInformation = destination.ExportCapture(false, surface, captureDetails);
                    if (EditorDestination.DESIGNATION.Equals(destination.Designation) && exportInformation.ExportMade) {
                        canDisposeSurface = false;
                    }
                }
            }
            if (canDisposeSurface) {
                surface.Dispose();
            }
        }
예제 #50
0
		/// <summary>
		/// Handle the key down event
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		void CaptureFormKeyDown(object sender, KeyEventArgs e) {
			int step = _isCtrlPressed ? 10 : 1;

			switch (e.KeyCode) {
				case Keys.Up:
					Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y - step);
					break;
				case Keys.Down:
					Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y + step);
					break;
				case Keys.Left:
					Cursor.Position = new Point(Cursor.Position.X - step, Cursor.Position.Y);
					break;
				case Keys.Right:
					Cursor.Position = new Point(Cursor.Position.X + step, Cursor.Position.Y);
					break;
				case Keys.ShiftKey:
					// Fixmode
					if (_fixMode == FixMode.None) {
						_fixMode = FixMode.Initiated;
					}
					break;
				case Keys.ControlKey:
					_isCtrlPressed = true;
					break;
				case Keys.Escape:
					// Cancel
					DialogResult = DialogResult.Cancel;
					break;
				case Keys.M:
					// Toggle mouse cursor
					_capture.CursorVisible = !_capture.CursorVisible;
					Invalidate();
					break;
				//// TODO: Enable when the screen capture code works reliable
				//case Keys.V:
				//	// Video
				//	if (capture.CaptureDetails.CaptureMode != CaptureMode.Video) {
				//		capture.CaptureDetails.CaptureMode = CaptureMode.Video;
				//	} else {
				//		capture.CaptureDetails.CaptureMode = captureMode;
				//	}
				//	Invalidate();
				//	break;
				case Keys.Z:
					if (_captureMode == CaptureMode.Region) {
						// Toggle zoom
						Conf.ZoomerEnabled = !Conf.ZoomerEnabled;
						InitializeZoomer(Conf.ZoomerEnabled);
						Invalidate();
					}
					break;
				case Keys.Space:
					// Toggle capture mode
					switch (_captureMode) {
						case CaptureMode.Region:
							// Set the window capture mode
							_captureMode = CaptureMode.Window;
							// "Fade out" Zoom
							InitializeZoomer(false);
							// "Fade in" window
							_windowAnimator = new RectangleAnimator(new Rectangle(_cursorPos, Size.Empty), _captureRect, FramesForMillis(700), EasingType.Quintic, EasingMode.EaseOut);
							_captureRect = Rectangle.Empty;
							Invalidate();
							break;
						case CaptureMode.Window:
							// Set the region capture mode
							_captureMode = CaptureMode.Region;
							// "Fade out" window
							_windowAnimator.ChangeDestination(new Rectangle(_cursorPos, Size.Empty), FramesForMillis(700));
							// Fade in zoom
							InitializeZoomer(Conf.ZoomerEnabled);
							_captureRect = Rectangle.Empty;
							Invalidate();
							break;
					}
					_selectedCaptureWindow = null;
					OnMouseMove(this, new MouseEventArgs(MouseButtons.None, 0, Cursor.Position.X, Cursor.Position.Y, 0));
					break;
				case Keys.Return:
					// Confirm
					if (_captureMode == CaptureMode.Window) {
						DialogResult = DialogResult.OK;
					} else if (!_mouseDown) {
						HandleMouseDown();
					} else if (_mouseDown) {
						HandleMouseUp();
					}
					break;
			}
		}
예제 #51
0
 public ModeChangedEventArgs(CaptureMode newMode)
 {
     this.Mode = newMode;
 }
예제 #52
0
 public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor)
     : this(captureMode)
 {
     _captureMouseCursor = captureMouseCursor;
 }
예제 #53
0
 public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor, IDestination destination)
     : this(captureMode, captureMouseCursor)
 {
     _capture.CaptureDetails.AddDestination(destination);
 }
예제 #54
0
 protected override void OnCapture(IInputElement element, CaptureMode captureMode)
 {
     Mouse.PrimaryDevice.Capture(element, captureMode);
 }
예제 #55
0
        void cam_CaptureCompleted(object sender, CameraOperationCompletedEventArgs e)
        {
            Debug.WriteLine("cam_CaptureCompleted");

            switch (cm)
            {
                case CaptureMode.CaptureFrame:
                    cm = CaptureMode.CapturePhoto;
                    break;
                case CaptureMode.CapturePhoto:
                    cm = CaptureMode.PostView;
                    //cm = CaptureMode.CaptureFrame;
                    //Deployment.Current.Dispatcher.BeginInvoke(delegate()
                    //{
                    //    NavigationService.Navigate(new Uri("/Postview.xaml", UriKind.Relative));
                    //    lastView.Visibility = Visibility.Collapsed;
                    //    GuidelineIn.Begin();
                    //});
                    break;
            }

            // Increments the savedCounter variable used for generating JPEG file names.
            savedCounter++;
            savedCounter %= 2; // toggle 0 and 1
        }
 public static bool Capture(System.Windows.IInputElement element, CaptureMode captureMode)
 {
   return default(bool);
 }
예제 #57
0
        internal void ChangeStylusCapture(IInputElement stylusCapture, CaptureMode captureMode, int timestamp)
#endif
        {
            // if the capture changed...
            if(stylusCapture != _stylusCapture)
            {
                // Actually change the capture first.  Invalidate the properties,
                // and then send the events.
                IInputElement oldStylusCapture = _stylusCapture;
                using(Dispatcher.DisableProcessing()) // Disable reentrancy due to locks taken
                {
                    lock(_rtiCaptureChanged)
                    {
                        _stylusCapture = stylusCapture;
                        _captureMode = captureMode;

                        // We also need to figure out ahead of time if any plugincollections on this captured element (or a parent)
                        // for the penthread hittesting code.
                        _stylusCapturePlugInCollection = null;
                        if (stylusCapture != null)
                        {
                            UIElement uiElement = InputElement.GetContainingUIElement(stylusCapture as DependencyObject) as UIElement;
                            if (uiElement != null)
                            {
                                PresentationSource source = PresentationSource.CriticalFromVisual(uiElement as Visual);
                                                      
                                if (source != null)
                                {
                                    PenContexts penContexts = _stylusLogic.GetPenContextsFromHwnd(source);

                                    _stylusCapturePlugInCollection = penContexts.FindPlugInCollection(uiElement);
                                }
                            }
                        }
                    }
                }

#if MULTICAPTURE
                DetachFromPropertiesAffectingCapture(oldStylusCapture);
                AttachToPropertiesAffectingCapture(_stylusCapture);
                
                // Oddly enough, update the IsStylusCaptureWithin property first.  This is
                // so any callbacks will see the more-common IsStylusCaptureWithin property
                // set correctly.
                UIElement.StylusCaptureWithinProperty.OnOriginValueChanged(oldStylusCapture as DependencyObject, _stylusCapture as DependencyObject, ref _stylusCaptureWithinTreeState);
                
                // Invalidate the IsStylusCaptured properties.
                if (oldStylusCapture != null)
                {
                    var o = oldStylusCapture as DependencyObject;
                    o.SetValue(UIElement.IsStylusCapturedPropertyKey, false); // Same property for ContentElements
                }
                if (_stylusCapture != null)
                {
                    var o = _stylusCapture as DependencyObject;
                    o.SetValue(UIElement.IsStylusCapturedPropertyKey, true); // Same property for ContentElements
                }
#else
                _stylusLogic.UpdateStylusCapture(this, oldStylusCapture, _stylusCapture, timestamp);
#endif

                // Send the LostStylusCapture and GotStylusCapture events.
                if(oldStylusCapture != null)
                {
                    StylusEventArgs lostCapture = new StylusEventArgs(this, timestamp);
                    lostCapture.RoutedEvent=Stylus.LostStylusCaptureEvent;
                    lostCapture.Source= oldStylusCapture;
                    _stylusLogic.InputManagerProcessInputEventArgs(lostCapture);
                }
                if(_stylusCapture != null)
                {
                    StylusEventArgs gotCapture = new StylusEventArgs(this, timestamp);
                    gotCapture.RoutedEvent=Stylus.GotStylusCaptureEvent;
                    gotCapture.Source= _stylusCapture;
                    _stylusLogic.InputManagerProcessInputEventArgs(gotCapture);
                }

                // Now update the stylus over state (only if this is the current stylus and 
                // it is inrange).
                if (_stylusLogic.CurrentStylusDevice == this || InRange)
                {
                    if (_stylusCapture != null)
                    {
                        IInputElement inputElementHit = _stylusCapture;

                        // See if we need to update over for subtree mode.
                        if (CapturedMode == CaptureMode.SubTree && _inputSource != null && _inputSource.Value != null)
                        {
                            Point pt = _stylusLogic.DeviceUnitsFromMeasureUnits(GetPosition(null));
                            inputElementHit = FindTarget(_inputSource.Value, pt);
                        }

                        ChangeStylusOver(inputElementHit);
                    }
                    else
                    {
                        // Only try to update over if we have a valid input source.
                        if (_inputSource != null && _inputSource.Value != null)
                        {
                            Point pt = GetPosition(null); // relative to window (root element)
                            pt = _stylusLogic.DeviceUnitsFromMeasureUnits(pt); // change back to device coords.
                            IInputElement currentOver = GlobalHitTest(_inputSource.Value, pt);
                            ChangeStylusOver(currentOver);
                        }
                    }
                }


                // For Mouse StylusDevice we want to make sure Mouse capture is set up the same.
#if MULTICAPTURE
                if ((Mouse.PrimaryDevice.StylusDevice == this) && (Mouse.Captured != _stylusCapture || Mouse.CapturedMode != _captureMode))
#else
                if (Mouse.Captured != _stylusCapture || Mouse.CapturedMode != _captureMode)
#endif
                {
                    Mouse.Capture(_stylusCapture, _captureMode);
                }
            }
        }
예제 #58
0
 private void ChangeStylusCapture(IInputElement stylusCapture, CaptureMode captureMode, int timestamp)
예제 #59
0
        /////////////////////////////////////////////////////////////////////
        /// <summary>
        ///     Captures the stylus to a particular element.
        /// </summary>
        public bool Capture(IInputElement element, CaptureMode captureMode)
        {
            int timeStamp = Environment.TickCount;
            VerifyAccess();

            if (!(captureMode == CaptureMode.None || captureMode == CaptureMode.Element || captureMode == CaptureMode.SubTree))
            {
                throw new System.ComponentModel.InvalidEnumArgumentException("captureMode", (int)captureMode, typeof(CaptureMode));
            }

            if(element == null)
            {
                captureMode = CaptureMode.None;
            }

            if (captureMode == CaptureMode.None)
            {
                element = null;
            }

            // Validate that element is either a UIElement or a ContentElement
            DependencyObject doStylusCapture = element as DependencyObject;
            if (doStylusCapture != null && !InputElement.IsValid(element))
            {
                throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, doStylusCapture.GetType()));
            }

            if ( doStylusCapture != null )
            {
                doStylusCapture.VerifyAccess();
            }

            bool success = false;

            // The element we are capturing to must be both enabled and visible.

            UIElement e = element as UIElement;
            if (e != null)
            {
                if(e.IsVisible || e.IsEnabled)
                {
                    success = true;
                }
            }
            else
            {
                ContentElement ce = element as ContentElement;
                if (ce != null)
                {
                    if(ce.IsEnabled) // There is no IsVisible property for ContentElement
                    {
                        success = true;
                    }
                }
                else
                {
                    // Setting capture to null.
                    success = true;
                }
            }

            if(success)
            {
                ChangeStylusCapture(element, captureMode, timeStamp);
            }
            return success;
        }
예제 #60
-1
		/// <summary>
		/// This creates the capture form
		/// </summary>
		/// <param name="capture"></param>
		/// <param name="windows"></param>
		public CaptureForm(ICapture capture, List<WindowDetails> windows) {
			if (_currentForm != null) {
				LOG.Warn("Found currentForm, Closing already opened CaptureForm");
				_currentForm.Close();
				_currentForm = null;
				Application.DoEvents();
			}
			_currentForm = this;

			// Enable the AnimatingForm
			EnableAnimation = true;

			// clean up
			FormClosed += ClosedHandler;

			_capture = capture;
			_windows = windows;
			_captureMode = capture.CaptureDetails.CaptureMode;

			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			// Only double-buffer when we are not in a TerminalServerSession
			DoubleBuffered = !isTerminalServerSession;
			Text = "Greenshot capture form";

			// Make sure we never capture the captureform
			WindowDetails.RegisterIgnoreHandle(Handle);
			// Unregister at close
			FormClosing += ClosingHandler;

			// set cursor location
			_cursorPos = WindowCapture.GetCursorLocationRelativeToScreenBounds();

			// Initialize the animations, the window capture zooms out from the cursor to the window under the cursor 
			if (_captureMode == CaptureMode.Window) {
				_windowAnimator = new RectangleAnimator(new Rectangle(_cursorPos, Size.Empty), _captureRect, FramesForMillis(700), EasingType.Quintic, EasingMode.EaseOut);
			}

			// Set the zoomer animation
			InitializeZoomer(Conf.ZoomerEnabled);

			SuspendLayout();
			Bounds = capture.ScreenBounds;
			ResumeLayout();
			
			// Fix missing focus
			ToFront = true;
			TopMost = true;
		}