Пример #1
0
        //CaptureScreenToFile
        public Bitmap CaptureDeskTopRectangle(Rectangle CapRect, int CapRectWidth, int CapRectHeight)
        {
            /// Returns BitMap of the region of the desktop, similar to CaptureWindow, but can be used to
            /// create a snapshot of the desktop when no handle is present, by passing in a rectangle
            /// Grabs snapshot of entire desktop, then crops it using the passed in rectangle's coordinates
            ScreenShot.ScreenCapture SC = new ScreenShot.ScreenCapture();
            Bitmap    bmpImage          = new Bitmap(SC.CaptureScreen());
            Bitmap    bmpCrop           = new Bitmap(CapRectWidth, CapRectHeight, bmpImage.PixelFormat);
            Rectangle recCrop           = new Rectangle(CapRect.X, CapRect.Y, CapRectWidth, CapRectHeight);
            Graphics  gphCrop           = Graphics.FromImage(bmpCrop);
            Rectangle recDest           = new Rectangle(0, 0, CapRectWidth, CapRectHeight);

            gphCrop.DrawImage(bmpImage, recDest, recCrop.X, recCrop.Y, recCrop.Width, recCrop.Height, GraphicsUnit.Pixel);
            return(bmpCrop);
        }
Пример #2
0
        private static void CaptureWindow(IntPtr handle)
        {
            ScreenShot.ScreenCapture SC = new ScreenShot.ScreenCapture();

            try
            {
                Image bmTemp = SC.CaptureWindow(handle);
                bmTemp.Save(strFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);

                output += "Window captured to:  " + strFilePath + "\n";
            }
            catch (Exception ex)
            {
                output += ex.Message + "\n";
            }
        }
Пример #3
0
        private static void TakeScreenshot()
        {
            ScreenShot.ScreenCapture SC = new ScreenShot.ScreenCapture();

            try
            {
                Image bmTemp = SC.CaptureScreen();
                bmTemp.Save(strFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);

                output += "Desktop captured to:  " + strFilePath + "\n";
            }
            catch (Exception ex)
            {
                output += ex.Message + "\n";
            }
        }
Пример #4
0
        public void CaptureWindow(SetImage pass)
        {
            Profile profile = (Profile)profileComboBox.SelectedItem;

            if (profile == null)
            {
                MessageBox.Show("Please select a Profile", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Process[] players = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(profile.ApplicationPath));

            if (players.Length == 0)
            {
                MessageBox.Show("No game window detected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            IntPtr player = players[0].MainWindowHandle;

            Rectangle pic = new Rectangle();

            GetClientRect(player, ref pic);

            ScreenShot.ScreenCapture screenshot = new ScreenShot.ScreenCapture();
            Bitmap image = (Bitmap)screenshot.CaptureWindow(player);

            int border = (image.Width - pic.Width) / 2;
            int top    = image.Height - pic.Height - border;

            Rectangle crop = new Rectangle(border, top, pic.Width, pic.Height);

            if (IsIconic(player) | crop.IsEmpty | crop.Width == 0 | crop.Height == 0)
            {
                MessageBox.Show("Please make sure the game is not minimized", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                SetForegroundWindow((int)player);
                SendKeys.SendWait("~");
                return;
            }

            else
            {
                Bitmap cropped = image.Clone(crop, image.PixelFormat);
                pass(cropped);
            }
        }