Screenshot taking and Camera.Render problems

Hi all!

We are porting the Unity game from iOS and Android to Windows Phone 8 and experiencing some problems with screenshot taking and using the Camera.Render.

I would appreciate any advice or help here.

So let’s start:

  1. We use Texture2D.ReadPixels to get the screenshot. On iOS and Android this works just fine as well as on the Windows Phone 8 in Unity editor, but on the Windows Phone 8 device we receive a black texture. I tried this method with different TextureFormat values but still have the same issue (the texture is of the proper size but with zero pixels).

  2. So then I tried using the Application.CaptureScreenshot method which gives me a corrupted texture (but that as I know is a known bug as menshioned here http://forum.unity3d.com/threads/194725-Bug-on-Screenshot).

  3. Then I tried writing a method in plugin which uses the Windows Phone 8 API to take a screenshot but this approach failed as well.
    I was using the WritableBitmap with the DrawingSurfaceBackgroundGrid property of MainPage as UIElement to render. But it gave me the black texture as well (proper size but zero pixels). Is it any way to get the screenshot from plugins?

  4. So then I decided to use Camera.Render method but faced another problem. My code is almost like in Unity Scripting example and it works fine on Unity Editor but gives me rotated by 90 degress texture on the device. So the texture has the proper size but the image itself is rotated and streched to fit the given size. This also happens on perspective or orthographic cameras in the other code not related to screenshot taking (which also works in editor, Android and iOS).

So for all issues the question is:
What could be a problem here? Is it probably some WP8 Unity implementation issue?

I don’t have my code right now with me but can send it later if it would be needed.

We are using Unity 4.2.1. and testing on HTC 8X and HTC 8S.

Thanks in advance)

We are having exactly the same experience. Did you eve find an answer to this question? We simply need the screen shots for save games. Would be sad to loose that ability.

Application.CaptureScreenshot was fixed a while ago. What Unity version are you on?

I need the image in a texture saving it to a file on the windows phone platform is problematic.

Did you try Texture2D.ReadPixels?

I have solved this issue with a little hack.

	void LateUpdate() {
		if (takeHiResShot) {
			GameObject go=new GameObject();
			go.AddComponent(typeof(Camera));
			Camera c=go.GetComponent<Camera>();
			c.CopyFrom(camera);

			takeHiResShot = false;
			int resWidth = (int)(camera.GetScreenWidth()*scale);
			int resHeight = (int)(camera.GetScreenHeight()*scale);
			RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
			c.targetTexture = rt;
			Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
			c.Render();
			RenderTexture.active = rt;
			screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
			c.targetTexture = null;
			RenderTexture.active = null;
			Destroy(rt);
			Destroy(go);
			if (imageCallBack!=null){
				imageCallBack.ScreenShotDelivery(screenShot);
			}else{
				byte[] bytes = screenShot.EncodeToPNG();
				string filename = ScreenShotName(resWidth, resHeight);
				// TODO we need this back System.IO.File.WriteAllBytes(filename, bytes);
				Debug.Log(string.Format("Took screenshot to: {0}", filename));
			}
		}
	}

I simply create a new camera copy settings from the old one use that camera for the screen shot then destroy it when done. Bit messy but hey I don’t make screen shots all the time so it will do.