使用两点捕获屏幕截图
Capture a screenshot using two points
我怎样才能截取一个屏幕截图给它两个点并基本上创建一个矩形屏幕截图或其他东西?
我用过这个: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;
}
gfx.CopyFromScreen(rect2.Left, rect2.Top, 0, 0, image.Size, CopyPixelOperation.SourceCopy);
我怎样才能截取一个屏幕截图给它两个点并基本上创建一个矩形屏幕截图或其他东西?
我用过这个: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;
}
gfx.CopyFromScreen(rect2.Left, rect2.Top, 0, 0, image.Size, CopyPixelOperation.SourceCopy);