如何捕获截图,给它两个点,基本上创建一个矩形截图或什么?
我用过这个:How to create a RectangleF using two PointF?
但它似乎没有得到我想要的矩形截图,它将我带到屏幕的一角。
private void KListener_KeyDown(object sender, RawKeyEventArgs args)
{
if (args.Key.ToString() == "F5")
{
Program.FirstPos = System.Windows.Forms.Cursor.Position;
System.Media.SystemSounds.Asterisk.Play();
}
else if (args.Key.ToString() == "F6")
{
Program.SecondPos = System.Windows.Forms.Cursor.Position;
System.Media.SystemSounds.Asterisk.Play();
}
}
public Bitmap CaptureScreen()
{
RectangleF rect2 = GetRectangle(Program.FirstPos, Program.SecondPos);
var image = new Bitmap((int)rect2.Width, (int)rect2.Height, PixelFormat.Format24bppRgb);
var gfx = Graphics.FromImage(image);
gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
image.Save("C:\\Users\\DreTaX\\Documents\\teszt", ImageFormat.Jpeg);
return image;
}
答案 0 :(得分:1)
gfx.CopyFromScreen(rect2.Left,rect2.Top,0,0,image.Size,CopyPixelOperation.SourceCopy);