Demo entry 6623311

1

   

Submitted by anonymous on Jun 07, 2017 at 09:49
Language: C#. Code size: 1.4 kB.

public void captureProgram(int targetHandle)
        {
            moveTopMostPlayer(targetHandle);
            RECT pRect;
            GetWindowRect((IntPtr)targetHandle, out pRect);
            Rectangle rect = Screen.PrimaryScreen.Bounds;

            System.Drawing.Size cSize = new System.Drawing.Size();
            cSize.Width = pRect.Right - pRect.Left;
            cSize.Height = pRect.Bottom - pRect.Top;

            int bitsPerPixel = Screen.PrimaryScreen.BitsPerPixel;
            PixelFormat pixelFormat = PixelFormat.Format32bppArgb;
            if (bitsPerPixel <= 16)
            {
                pixelFormat = PixelFormat.Format16bppRgb565;
            }
            if (bitsPerPixel == 24)
            {
                pixelFormat = PixelFormat.Format24bppRgb;
            }

            Bitmap bmp = new Bitmap(cSize.Width, cSize.Height, pixelFormat);
            using (Graphics gr = Graphics.FromImage(bmp))
            {
                gr.CopyFromScreen(pRect.Left, pRect.Top, 0, 0, rect.Size);
            }
            
            // jsonSettingFile의 ScreenPath 참조
            bmp.Save(jsonSettingFile.screenshotPath + "\\" + getscreenshotname() + ".png");
            ttNoti_pbRecentCapture.Image = (Bitmap)bmp.Clone();
            bmp.Dispose();
            moveFreeTopMostPlayer(targetHandle);
        }

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).