/// <summary> /// Performs the specified type of capture action and displays the image /// </summary> /// <param name="action">The action to perform</param> private void PerformAction(CaptureActions action) { Image image = null; switch (action) { case CaptureActions.Desktop: image = (Image)ScreenCapturing.GetDesktopWindowCaptureAsBitmap(); break; case CaptureActions.Window: image = (Image)ScreenCapturing.GetWindowCaptureAsBitmap((int)this.Handle); break; case CaptureActions.SmallIcon: image = (Image)ScreenCapturing.GetWindowSmallIconAsBitmap((int)this.Handle); break; case CaptureActions.LargeIcon: image = (Image)ScreenCapturing.GetWindowLargeIconAsBitmap((int)this.Handle); break; default: // if it's clear we'll just display a null image break; } ; this.DisplayImage(image, true, PictureBoxSizeMode.Normal /* doesn't matter as audo decide sizing is enabled */); }
/// <summary> /// Occurs when the user wants to capture the window that we've captured /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnButtonCaptureClicked(object sender, EventArgs e) { try { // parse the window handle int handle = int.Parse(_textBoxHandle.Text); // capture that window Image image = ScreenCapturing.GetWindowCaptureAsBitmap(handle); // fire our image read event, which the main window will display for us this.OnImageReadyForDisplay(image); } catch (Exception ex) { Debug.WriteLine(ex); } }
/// <summary> /// Gets a byte array of a bitmap for the window specified by the handle /// </summary> /// <param name="hWnd"></param> /// <returns></returns> public static byte[] GetWindowCaptureAsByteArray(int handle) { return(ScreenCapturing.GetBytes(ScreenCapturing.GetWindowCaptureAsBitmap(handle))); }
/// <summary> /// Gets a byte array of a bitmap for the desktop window /// </summary> /// <returns></returns> public static byte[] GetDesktopWindowCaptureAsByteArray() { return(ScreenCapturing.GetBytes(ScreenCapturing.GetDesktopWindowCaptureAsBitmap())); }