CaptureScreenshot without UI,

(I use Unity 4.6)
I’m trying to capture a screenshot image without GUI if the button is clicked.
A part of my script is as follows.

private bool mscreencapturemode = false;

...

public void OnClickScreenCaptureButton() {
	mscreencapturemode = true;
	GameObject.Find("MyCanvas").GetComponent<Canvas>().enabled = false;
}

...

void Update () {
	if (mscreencapturemode) {
		Application.CaptureScreenshot("screenshot.png");
		GameObject.Find("MyCanvas").GetComponent<Canvas>().enabled = true;
		mscreencapturemode = false;
	}
}

When I run on my Android tablet and touch the button, the button is disappeared from the screen, so it seems to success.
However, in the screenshot image which is obtained by the script, the button is also captured.

How can I get the screenshot image without GUI?

Thanks,
,

I was working on something similar and stumbled upon this thread. There’s a slight flicker on the UI when capturing the screenshot, but it kinda works for me. Hope it helps

public void OnClickScreenCaptureButton()
{
   StartCoroutine(CaptureScreen());
}

public IEnumerator CaptureScreen()
{
   // Wait till the last possible moment before screen rendering to hide the UI
   yield return null;
   GameObject.Find("MyCanvas").GetComponent<Canvas>().enabled = false;

   // Wait for screen rendering to complete
   yield return new WaitForEndOfFrame();

   // Take screenshot
   Application.CaptureScreenshot("screenshot.png");

   // Show UI after we're done
   GameObject.Find("MyCanvas").GetComponent<Canvas>().enabled = true;
}

Application.CaptureScreenshot() api have become redundant, see the documentation
below code by @pixpusher2 works with slight changes.

// Take screenshot
//Application.CaptureScreenshot("screenshot.png");
ScreenCapture.CaptureScreenshot(Application.persistentDataPath+"/screenshot.png");//use this

Hey,

The button would not turn off until the end of the frame. You are then taking a picture of that frame which has the UI enabled. What I would suggest is putting a simple delay after the button is pressed. Then you can take a screen shot.

Regards

it looks like you’re setting mscreencapturemode = true; before your actually hide the canvas

try moving that line one line down like this

public void OnClickScreenCaptureButton() {
     GameObject.Find("MyCanvas").GetComponent<Canvas>().enabled = false;
     mscreencapturemode = true;
  }

not sure if this will solve it, but it’s worth a try :slight_smile:

What if I only need to hide a child of my canvas ?

The code by @pixpusher2 works perfectly along with the suggestion from @monstrXR . But the problem I am facing is that it is only saving one screenshot per runtime. How can I save multiple screenshot per runtime on click? This is the code i am using now

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//using System.IO;

public class ScreenShot : MonoBehaviour
{
    string ScreenShotfilename = string.Format("Screenshot-{0:yyyy-MM-dd_hh-mm-ss-tt}.png", System.DateTime.Now);

    public void OnClickScreenCaptureButton()
    {
        StartCoroutine(CaptureScreen());
        StopCoroutine(CaptureScreen());
    }
    public IEnumerator CaptureScreen()
    {
        // Wait till the last possible moment before screen rendering to hide the UI
        yield return null;
        GameObject.Find("Canvas").GetComponent<Canvas>().enabled = false;

        // Wait for screen rendering to complete
        yield return new WaitForEndOfFrame();

        // Take screenshot
        //Application.CaptureScreenshot("screenshot.png");
        ScreenCapture.CaptureScreenshot(Application.persistentDataPath + "/"+ ScreenShotfilename); //use this

        // Show UI after we're done
        GameObject.Find("Canvas").GetComponent<Canvas>().enabled = true;

        Debug.Log("ScreenShot");
        Debug.Log(Application.persistentDataPath);
    }
}