public static Bitmap CaptureWindow(IntPtr wndHandle, Point point, int width, int height) { User32.Rect windowRect; User32.GetWindowRect(wndHandle, out windowRect); var windowWidth = windowRect.right - windowRect.left; var windowHeight = windowRect.bottom - windowRect.top; var bmp = new Bitmap(windowWidth, windowHeight, PixelFormat.Format32bppArgb); using(var graphics = Graphics.FromImage(bmp)) { var hdc = graphics.GetHdc(); try { User32.PrintWindow(wndHandle, hdc, 0); } finally { graphics.ReleaseHdc(hdc); } } var cRect = new User32.Rect(); User32.GetClientRect(wndHandle, ref cRect); var cWidth = cRect.right - cRect.left; var cHeight = cRect.bottom - cRect.top; var captionHeight = windowHeight - cHeight > 0 ? SystemInformation.CaptionHeight : 0; return bmp.Clone( new Rectangle((windowWidth - cWidth) / 2 + point.X, (windowHeight - cHeight - captionHeight) / 2 + captionHeight + point.Y, width, height), PixelFormat.Format32bppArgb); }
public static Bitmap CaptureAllCategories(bool firstImage) { var proc = Process.GetProcessesByName("TheFinalBudget")[0]; var rect = new User32.Rect(); User32.GetWindowRect(proc.MainWindowHandle, ref rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; using (var bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { using (Graphics graphics = Graphics.FromImage(bmp)) { graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new System.Drawing.Size(width, height), CopyPixelOperation.SourceCopy); System.Drawing.Rectangle cropSection = new System.Drawing.Rectangle(5, 30, 1100, 717); if (!firstImage) { cropSection = new System.Drawing.Rectangle(5, 40, 615, 650); } return(CropImage(bmp, cropSection)); } } }
public Image CaptureWindow(IntPtr handle) { // get te hDC of the target window IntPtr hdcSrc = User32.GetWindowDC(handle); // get the size var windowRect = new User32.Rect(); User32.GetWindowRect(handle, ref windowRect); int width = windowRect.right - windowRect.left; int height = windowRect.bottom - windowRect.top; // create a device context we can copy to IntPtr hdcDest = Gdi32.CreateCompatibleDC(hdcSrc); // create a bitmap we can copy it to, // using GetDeviceCaps to get the width/height IntPtr hBitmap = Gdi32.CreateCompatibleBitmap(hdcSrc, width, height); // select the bitmap object IntPtr hOld = Gdi32.SelectObject(hdcDest, hBitmap); // bitblt over Gdi32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, Gdi32.Srccopy); // restore selection Gdi32.SelectObject(hdcDest, hOld); // clean up Gdi32.DeleteDC(hdcDest); User32.ReleaseDC(handle, hdcSrc); // get a .NET image object for it Image img = Image.FromHbitmap(hBitmap); // free up the Bitmap object Gdi32.DeleteObject(hBitmap); return img; }
public void capturarteladbo(int ii) { string procName = "DBOG"; Process[] procs = Process.GetProcessesByName(procName); var rect = new User32.Rect(); int width = 0; int height = 0; foreach (Process proc in procs) { User32.GetWindowRect(proc.MainWindowHandle, ref rect); width = rect.right - rect.left; height = rect.bottom - rect.top; // break foreach if an realistic rectangle found => main process found if (width != 0 && height != 0) { break; } } var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bmp); graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); //bmp.Save("C:/Users/Thayná/Desktop/Ju/DBO Bot/imagens/img" + Convert.ToString(ii) + ".jpg", ImageFormat.Jpeg); //bmp.Save("C:/Users/Thayná/Desktop/Ju/DBO Bot/imagens/test.png", ImageFormat.Png); }
public static Bitmap CaptureProcessWindow(string procName, out User32.Rect formRect) { formRect = new User32.Rect(); var procs = Process.GetProcessesByName(procName); if (procs.Length == 0) { return(null); } var rect = new User32.Rect(); var proc = procs.Where(p => { User32.GetWindowRect(p.MainWindowHandle, ref rect); return(rect.left != 0 && rect.right != 0); }).First(); int width = rect.right - rect.left; int height = rect.bottom - rect.top; var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bmp); graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); formRect = rect; return(bmp); }
private void CaptureApp(string processName) { try { var process = Process.GetProcessesByName(processName)[0]; MessageBox.Show(process.ToString()); var rect = new User32.Rect(); User32.GetWindowRect(process.MainWindowHandle, ref rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bmp); graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); bmp.Save(savePath + processName + ".png", ImageFormat.Png); Rectangle statSection = new Rectangle(start, new Size(415 - 13, 680 - 450)); Bitmap statBmp = CutImg(bmp, statSection); statBmp.Save(savePath + "Tembala stat.png", ImageFormat.Png); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public IVideoSource CaptureVideoSource() { var rect = new User32.Rect(); User32.GetWindowRect(_process.MainWindowHandle, ref rect); return(new ScreenCaptureStream(rect.ToRectangle())); }
private static void ResetTerminal(Process process, User32.Rect originalRect) { var bounds = GetScreenWithCursor().Bounds; // Restore taskbar icon User32.SetWindowLong(process.MainWindowHandle, User32.GWL_EX_STYLE, (User32.GetWindowLong(process.MainWindowHandle, User32.GWL_EX_STYLE) | User32.WS_EX_TOOLWINDOW) & User32.WS_EX_APPWINDOW); // Reset position User32.MoveWindow(process.MainWindowHandle, originalRect.Left, originalRect.Top, (originalRect.Right - originalRect.Left), (originalRect.Bottom - originalRect.Top), true); }
public static int[] CalculateDesktopBounds() { var rect = new User32.Rect(); User32.GetWindowRect(User32.GetDesktopWindow(), ref rect); var bounds = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); int[] result = { bounds.Width, bounds.Height }; return(result); }
public static void SaveScreenshot(Stream stream, FormatImage format) { System.Diagnostics.Process p = Warframe.GetProcess(); if (p == null) { throw new Exception(); } IntPtr ptr = p.MainWindowHandle; User32.Rect rect = new User32.Rect(); User32.GetWindowRect(ptr, ref rect); int width = rect.Right - rect.Left; int height = rect.Bottom - rect.Top; if (height == 0 || width == 0) { return; } using (Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb)) { using (var graphics = Graphics.FromImage(bitmap)) { graphics.CopyFromScreen(rect.Left, rect.Top, 0, 0, new Size(width, height)); graphics.Save(); graphics.Dispose(); Bitmap bit; switch (format) { case FormatImage.TIFF: bit = MakeGrayscale3(bitmap); bit.Save(stream, System.Drawing.Imaging.ImageFormat.Tiff); bit.Dispose(); break; case FormatImage.PNG: default: bit = MakeGrayscale3(bitmap); bit.Save(stream, System.Drawing.Imaging.ImageFormat.Png); bit.Dispose(); #if DEBUG //using (FileStream file = new FileStream("shot_" + DateTime.Now.ToString("HH_mm_ss") + ".png", FileMode.Create, FileAccess.Write)) //{ // ((MemoryStream)stream).WriteTo(file); //} #endif break; } } } }
public static Bitmap CaptureWindowDifferentFunction(IntPtr handle) { var rect = new User32.Rect(); User32.GetWindowRect(handle, ref rect); var bounds = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); var result = new Bitmap(bounds.Width, bounds.Height); using (var graphics = Graphics.FromImage(result)) { graphics.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size); } return(result); }
public Bitmap CaptureApplication() { Process proc = Process.GetCurrentProcess(); var rect = new User32.Rect(); User32.GetWindowRect(proc.MainWindowHandle, ref rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bmp); graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new System.Drawing.Size(width, height), CopyPixelOperation.SourceCopy); return bmp; }
public void CaptureApplication(string procName, int i) { var proc = Process.GetProcessesByName(procName)[0]; var rect = new User32.Rect(); User32.GetWindowRect(proc.MainWindowHandle, ref rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bmp); graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); bmp.Save("frame" + i + ".png", ImageFormat.Png); }
private void btnSaveScreenshotResults_Click(object sender, EventArgs e) { var proc = Process.GetCurrentProcess(); var rect = new User32.Rect(); User32.GetWindowRect(proc.MainWindowHandle, ref rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bmp); graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); // Displays a SaveFileDialog so the user can save the Image SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Jpeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif"; saveFileDialog1.Title = "Save Results"; saveFileDialog1.ShowDialog(); // If the file name is not an empty string open it for saving. if (saveFileDialog1.FileName != "") { // Saves the Image via a FileStream created by the OpenFile method. FileStream fs = (FileStream)saveFileDialog1.OpenFile(); // Saves the Image in the appropriate ImageFormat based upon the // File type selected in the dialog box. // NOTE that the FilterIndex property is one-based. switch (saveFileDialog1.FilterIndex) { case 1: bmp.Save(fs, ImageFormat.Jpeg); break; case 2: bmp.Save(fs, ImageFormat.Bmp); break; case 3: bmp.Save(fs, ImageFormat.Gif); break; } fs.Close(); } }
public static Bitmap CaptureApplication(IntPtr windowHandle) { var rect = new User32.Rect(); User32.GetWindowRect(windowHandle, ref rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; var bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb); Graphics graphics = Graphics.FromImage(bmp); graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); return(bmp); }
public void CaptureApplication() { var proc = Process.GetCurrentProcess(); var rect = new User32.Rect(); User32.GetWindowRect(proc.MainWindowHandle, ref rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bmp); graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new System.Drawing.Size(width, height), CopyPixelOperation.SourceCopy); bmp.Save("graph.png", ImageFormat.Png); }
public static Image CaptureWindow(IntPtr handle) { IntPtr hdcSrc = User32.GetWindowDC(handle); User32.Rect windowRect = new User32.Rect(); User32.GetWindowRect(handle, ref windowRect); int width = windowRect.right - windowRect.left; int height = windowRect.bottom - windowRect.top; IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc); IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height); IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap); GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY); GDI32.SelectObject(hdcDest, hOld); GDI32.DeleteDC(hdcDest); User32.ReleaseDC(handle, hdcSrc); Image img = Image.FromHbitmap(hBitmap); GDI32.DeleteObject(hBitmap); return img; }
public Bitmap CaptureApplication(string procName) { var proc = Process.GetProcessesByName(procName)[0]; var rect = new User32.Rect(); User32.GetWindowRect(proc.MainWindowHandle, ref rect); var width = rect.right - rect.left; var height = rect.bottom - rect.top; var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(bmp)) { graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); } return bmp; }
/// <summary> /// Is the given window minimized. /// </summary> /// <param name="winHandle">A handle to the window</param> /// <returns><c>true</c> if the window is minimized, <c>false</c> otherwise</returns> static private bool isMiniMized(IntPtr winHandle) { User32.Rect rect = new User32.Rect(); if (!User32.GetWindowRect(winHandle, out rect)) throw new ApplicationException("Could not get window position. Error code: " + User32.GetLastError()); return ((rect.Top == -32000) && (rect.Left == -32000)); }
public void CaptureApplication(string procName) { var proc = Process.GetProcessesByName(procName)[0]; var rect = new User32.Rect(); User32.GetWindowRect(proc.MainWindowHandle, ref rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; var bmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp); graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new System.Drawing.Size(width, height), System.Drawing.CopyPixelOperation.SourceCopy); bmp.Save("C:\\Users\\Rikesh\\Documents\\Kinect\\VirtueX\\TestersDatabase\\Skeleton\\Skeleton_files\\Skeleton"+i.ToString()+".jpg", ImageFormat.Jpeg); }