/// <summary> /// Takes screenshot of the window (supports multiple monitors) and then lets user to select the wanted area and returns that area. /// Also returns the rectangle of the selected part inside of the window. /// </summary> public static Image Snip(IntPtr hWnd, out Rectangle rect, PixelFormat format = PixelFormat.Format24bppRgb) { NativeWin32.SetForegroundWindow(hWnd); Rect r; if (!NativeWin32.GetWindowRect(hWnd, out r)) { rect = Rectangle.Empty; return(null); } rect = new Rectangle(Convert.ToInt32(r.X), Convert.ToInt32(r.Y), Convert.ToInt32(r.Width), Convert.ToInt32(r.Height)); var bmp = ScreenShot.Create(hWnd); Graph = Graphics.FromImage(bmp); Graph.SmoothingMode = SmoothingMode.None; using (var snipper = new SnippingTool(bmp) { SpecificWindowMode = true }) { snipper.Location = new Point(rect.Left, rect.Top); NativeWin32.SetForegroundWindow(snipper.Handle); if (snipper.ShowDialog() == DialogResult.OK) { rect = snipper.rcSelect; return(snipper.Image); } } rect = Rectangle.Empty; return(null); }
/// <summary> /// Takes screenshot of the window (supports multiple monitors) and then lets user to select the wanted area and returns that area. /// </summary> public static Image Snip(IntPtr hWnd, PixelFormat format = PixelFormat.Format24bppRgb) { NativeWin32.SetForegroundWindow(hWnd); Rect r; if (!NativeWin32.GetWindowRect(hWnd, out r)) return null; var bmp = ScreenShot.Create(hWnd); Graph = Graphics.FromImage(bmp); Graph.SmoothingMode = SmoothingMode.None; using (var snipper = new SnippingTool(bmp) {SpecificWindowMode = true}) { snipper.Location = new Point(Convert.ToInt32(r.Left), Convert.ToInt32(r.Top)); NativeWin32.SetForegroundWindow(snipper.Handle); if (snipper.ShowDialog() == DialogResult.OK) { return snipper.Image; } } return null; }
/// <summary> /// Takes screenshot of the screen (supports multiple monitors) and then lets user to select the wanted area and returns that area. /// Also returns the rectangle of the selected part inside of the window. /// </summary> public static Image Snip(out Rectangle rect, PixelFormat format = PixelFormat.Format24bppRgb) { MultiScreenSize m_MultiScreenSize = FindMultiScreenSize(); var bmp = new Bitmap(m_MultiScreenSize.maxRight - m_MultiScreenSize.minX, m_MultiScreenSize.maxBottom - m_MultiScreenSize.minY, format); Graph = Graphics.FromImage(bmp); Graph.SmoothingMode = SmoothingMode.None; BitmapSize = bmp.Size; using (var snipper = new SnippingTool(bmp)) { snipper.Location = new Point(m_MultiScreenSize.minX, m_MultiScreenSize.minY); if (snipper.ShowDialog() == DialogResult.OK) { rect = snipper.rcSelect; return(snipper.Image); } } rect = Rectangle.Empty; return(null); }
/// <summary> /// Takes screenshot of the screen (supports multiple monitors) and then lets user to select the wanted area and returns that area. /// </summary> public static Image Snip(PixelFormat format = PixelFormat.Format24bppRgb) { MultiScreenSize m_MultiScreenSize = FindMultiScreenSize(); var bmp = new Bitmap(m_MultiScreenSize.maxRight - m_MultiScreenSize.minX, m_MultiScreenSize.maxBottom - m_MultiScreenSize.minY, format); Graph = Graphics.FromImage(bmp); Graph.SmoothingMode = SmoothingMode.None; BitmapSize = bmp.Size; using (var snipper = new SnippingTool(bmp)) { snipper.Location = new Point(m_MultiScreenSize.minX, m_MultiScreenSize.minY); if (snipper.ShowDialog() == DialogResult.OK) { return snipper.Image; } } return null; }