Graphics.CopyFromScreen返回黑屏 [英] Graphics.CopyFromScreen returns black screen

查看:445
本文介绍了Graphics.CopyFromScreen返回黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的应用程序,采用截屏并保存到文件夹的。它正常工作的大部分时间,但在某些情况下,例如当在团队要塞2或同时在OpenGL模式下运行魔兽争霸3之只返回一个完全黑色(或白色)的图像。有没有人有办法解决这个问题?

我现在用的是C#标准:

  BMP位图;
显卡GFX;
BMP =新位图(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,PixelFormat.Format32bppArgb);
GFX = Graphics.FromImage(bmpScreenshot);
gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,Screen.PrimaryScreen.Bounds.Y,0,0,Screen.PrimaryScreen.Bounds.Size,CopyPixelOperation.SourceCopy);
bmpScreenshot.Save(image.jpg文件,ImageFormat.Jpeg);
 

解决方案

窗口截图功能不从的DirectX复制数据表面。你所要做的是手动像这篇文章描述

I have a small application that takes screen shots and saves them to the folder its in. It works fine most of the time, but in some cases, for example while in Team Fortress 2 or while running Warcraft 3 in OpenGL mode it just returns a totally black(or white) image. Does anyone have a way to fix this?

I am using the c# standard:

Bitmap bmp;
Graphics gfx;
bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
gfx = Graphics.FromImage(bmpScreenshot);
gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
bmpScreenshot.Save("image.jpg", ImageFormat.Jpeg);

解决方案

Windows screenshot functions do not copy data from DirectX surfaces. You have to do that manually like described in this article.

这篇关于Graphics.CopyFromScreen返回黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆