Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从剪贴板获取屏幕截图?_C#_.net_.net 4.0 - Fatal编程技术网

C# 如何从剪贴板获取屏幕截图?

C# 如何从剪贴板获取屏幕截图?,c#,.net,.net-4.0,C#,.net,.net 4.0,我试着从剪贴板上截图。我编写了以下由打印键触发的代码: IDataObject obj = Clipboard.GetDataObject(); var formats = obj.GetFormats(); 但是“格式”是空的。www上的所有教程都告诉我这样做,但我无法解释上述行为 (我在Windows7x64上使用C#with E.NET4.0)您是否尝试了Clipboard.GetImage()方法 您是否尝试过剪贴板.GetImage()方法 你试过调用这个方法吗 提供的链接提供了

我试着从剪贴板上截图。我编写了以下由打印键触发的代码:

IDataObject obj = Clipboard.GetDataObject();
var formats = obj.GetFormats();
但是“格式”是空的。www上的所有教程都告诉我这样做,但我无法解释上述行为


(我在Windows7x64上使用C#with E.NET4.0)

您是否尝试了
Clipboard.GetImage()方法


您是否尝试过剪贴板.GetImage()方法


你试过调用这个方法吗

提供的链接提供了更多信息,其中还显示了如何检查剪贴板上是否存在图像(
ContainsImage
)-但您可能需要执行一些其他步骤,具体取决于对象写入剪贴板的时间


我甚至不知道有
GetFormats
方法,也找不到Windows窗体或WPF剪贴板类公开的方法。

您尝试调用该方法了吗

提供的链接提供了更多信息,其中还显示了如何检查剪贴板上是否存在图像(
ContainsImage
)-但您可能需要执行一些其他步骤,具体取决于对象写入剪贴板的时间


我甚至不知道
GetFormats
方法,也找不到Windows窗体或WPF剪贴板类公开的方法。

发现我的keylistener阻止了Windows keylistener。这就是windows没有将屏幕截图保存在剪贴板中的原因:-(

解决方法:

// get the bounding area of the screen containing (0,0)
// remember in a multidisplay environment you don't know which display holds this point
Drawing.Rectangle bounds = Forms.Screen.GetBounds(System.Drawing.Point.Empty);

// create the bitmap to copy the screen shot to
Drawing.Bitmap bitmap = new Drawing.Bitmap(bounds.Width, bounds.Height);

// now copy the screen image to the graphics device from the bitmap
using (Drawing.Graphics gr = Drawing.Graphics.FromImage(bitmap))
{
    gr.CopyFromScreen(Drawing.Point.Empty, Drawing.Point.Empty, bounds.Size);
}

发现my keylistener阻止了windows keylistener。这就是windows没有将屏幕截图保存在剪贴板中的原因:-(

解决方法:

// get the bounding area of the screen containing (0,0)
// remember in a multidisplay environment you don't know which display holds this point
Drawing.Rectangle bounds = Forms.Screen.GetBounds(System.Drawing.Point.Empty);

// create the bitmap to copy the screen shot to
Drawing.Bitmap bitmap = new Drawing.Bitmap(bounds.Width, bounds.Height);

// now copy the screen image to the graphics device from the bitmap
using (Drawing.Graphics gr = Drawing.Graphics.FromImage(bitmap))
{
    gr.CopyFromScreen(Drawing.Point.Empty, Drawing.Point.Empty, bounds.Size);
}

格式向我显示剪贴板中的格式,例如:PlainText、RTF、TIFF、PNG,…格式向我显示剪贴板中的格式,例如:PlainText、RTF、TIFF、PNG,…听起来你需要另一个打印键。你从未说过“但其他程序可以看到”.我想在我的帖子中解释截图是因为我可以通过它来画画,但我希望它是显而易见的;-)听起来你需要另一个打印键。你从来没有说过“但是另一个程序可以看到它”.我想在我的帖子中解释截图是因为我可以通过它来画画,但我希望它是显而易见的;-)你在使用WinForms吗?我在一个项目中尝试了这段代码,效果很好。使用wpf,也许就是这样,但为什么?你在使用WinForms吗?我在一个项目中尝试了这段代码,效果很好。使用wpf,也许就是这样,但为什么?
// get the bounding area of the screen containing (0,0)
// remember in a multidisplay environment you don't know which display holds this point
Drawing.Rectangle bounds = Forms.Screen.GetBounds(System.Drawing.Point.Empty);

// create the bitmap to copy the screen shot to
Drawing.Bitmap bitmap = new Drawing.Bitmap(bounds.Width, bounds.Height);

// now copy the screen image to the graphics device from the bitmap
using (Drawing.Graphics gr = Drawing.Graphics.FromImage(bitmap))
{
    gr.CopyFromScreen(Drawing.Point.Empty, Drawing.Point.Empty, bounds.Size);
}