2

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;
}
Community
  • 1
  • 1
pookie
  • 3,796
  • 6
  • 49
  • 105
  • Make a screenshot, save it to your asset folder, create a material for it, assign to whatever you want it to assign to? Or do i misunderstand completely? – yes May 07 '16 at 18:30
  • @yes Sorry, I have already considered that and was adding it to the post. Please see the update. – pookie May 07 '16 at 18:31
  • I still dont get what you try to archieve ^^ If its just a screenshot, just make a screenshot (as in use the printscreen key on your keyboard). Or do you want some sort of live steam of some desktop app? – yes May 07 '16 at 18:32
  • I want to capture all open windows on the desktop (MS Word, Excel, etc...) and display those captures on Game Objects. I do not want to write to disk. Live stream of desktop applications is pretty much it. – pookie May 07 '16 at 18:34
  • @yes He wants a screenshot of the whole device instead of screen shot of the game running in unity. For example, when unity app is not running full screen, he want to be able to take picture of what displayed on the screen. Both unity app and other things on the screen. – Programmer May 07 '16 at 18:34
  • @pookie What platform/os? – Programmer May 07 '16 at 18:35
  • @pookie I have a solution but will only post it when I am done testing it. It will take a while. – Programmer May 07 '16 at 18:41
  • @Programmer Looking forward to it! – pookie May 07 '16 at 18:45
  • @pookie It would good if you update your question with a code. Maybe a code that you use to load textures to a plane or 3D Object. You must have something. – Programmer May 07 '16 at 18:57
  • @pookie. Good. Will be back. – Programmer May 07 '16 at 19:02

1 Answers1

1

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.

Community
  • 1
  • 1
Bamdad
  • 726
  • 1
  • 11
  • 28