我已经阅读了很多有关在Unity3D中拍摄屏幕截图的示例,但是它们都解释了"游戏中"屏幕截图.我想在桌面上拍摄应用程序窗口的屏幕截图,并将其作为纹理绘制到GameObject上.
知道我该怎么做吗?我只使用过Unity3D几次,因此希望能获得一些指导,以了解这是否可行以及如何实现.
我知道我可以编写一些常规的C#应用程序,将Windows的输出捕获到文件中并在Unity3D中读取图像.但是,我不希望写入磁盘.
目前,我所能做的就是获取"游戏中"屏幕截图...
void LateUpdate()
{
//I know that I could load an image from file here...
Texture2D tex = new Texture2D(Screen.width, Screen.height);
tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
tex.Apply();
display.material.mainTexture = tex;
}
我认为您应该使用DLL.
在这里看一下这个答案.
他解释了如何在Visual C#中捕获Window句柄.我认为您可以找到一个桌面句柄(在Win7 +上)并捕获它,然后使用您的DLL将其发送给unity.
I have read a lot of examples about taking screenshots in Unity3D, but they all explain "in-game" screenshots. I would like to take a screenshot of an application window on my desktop and paint it onto a GameObject as a texture.
Any idea how I can go about doing this? I've only used Unity3D a few times and so would appreciate some guidance on if this is possible or not and how I might achieve this.
I know that I can write some regular C# application that will capture the outputs of windows to file and read the images in Unity3D. However, I would prefer not to write to disk.
At the moment, all I am able to do is get an "in-game" screenshot...
void LateUpdate()
{
//I know that I could load an image from file here...
Texture2D tex = new Texture2D(Screen.width, Screen.height);
tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
tex.Apply();
display.material.mainTexture = tex;
}
I think you should use DLLs.
Take a look here at this SO answer.
He explains how to capture a Window handle in Visual C#. I think you can find a Desktop handle (on Win7+) and capture it, then send it to unity using your DLL.
本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文