이것은 스크린과 마우스 커서를 캡쳐하는 데 사용하는 클래스입니다. 하지만 어떻게 든 폼을 화면 중간에 포착하지 않으면 화면 뒤쪽의 폼과 폼의 영역을 캡쳐하지 않습니다. 폼 자체는 아닙니다.양식없이 화면을 캡처하려면 어떻게해야합니까?
양식이 앞면에 있고 응용 프로그램이 실행되는 동안 단추를 클릭하거나 양식을 변경하는 경우에도 양식을 캡처하는 화면을 캡처하지 않는 것이 좋습니다. 무슨 뜻인지
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace ScreenShotDemo
{
public class ScreenCapture
{
[StructLayout(LayoutKind.Sequential)]
struct CURSORINFO
{
public Int32 cbSize;
public Int32 flags;
public IntPtr hCursor;
public POINTAPI ptScreenPos;
}
[StructLayout(LayoutKind.Sequential)]
struct POINTAPI
{
public int x;
public int y;
}
[DllImport("user32.dll")]
static extern bool GetCursorInfo(out CURSORINFO pci);
[DllImport("user32.dll")]
static extern bool DrawIcon(IntPtr hDC, int X, int Y, IntPtr hIcon);
const Int32 CURSOR_SHOWING = 0x00000001;
public static Bitmap CaptureScreen(bool CaptureMouse)
{
Bitmap result = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
try
{
using (Graphics g = Graphics.FromImage(result))
{
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
if (CaptureMouse)
{
CURSORINFO pci;
pci.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(CURSORINFO));
if (GetCursorInfo(out pci))
{
if (pci.flags == CURSOR_SHOWING)
{
DrawIcon(g.GetHdc(), pci.ptScreenPos.x, pci.ptScreenPos.y, pci.hCursor);
g.ReleaseHdc();
}
}
}
}
}
catch
{
result = null;
}
return result;
}
}
는 내가 그것을 실행중인 양식을 볼 것이며, 내가 양식을 볼 수 없습니다 페인트와 내가 그것을 편집 할 경우 상황이 버튼 있지만 촬영 한 스크린 샷을 클릭하여 변경할 수있을 것입니다.
이 내가 캡처 만드는 방법을 Form1에 있습니다
private void StartRecording_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
그리고 타이머 1 틱 이벤트 : (사용하여 비트 맵 = (비트 맵) ScreenCapture.CaptureScreen을 :
이private void timer1_Tick(object sender, EventArgs e)
{
using (bitmap = (Bitmap)ScreenCapture.CaptureScreen(true))
{
ffmp.PushFrame(bitmap);
}
}
이 줄은 실제 촬영을을 (true))
당신이 클릭을 제어하는 종료 코드를 다시 사용하는 것을 고려를이 더 나은 솔루션입니다. –