Hi,
to store a screenshot with a higher resolution, I use a RenderTexture (based on several threads).
This is working in the editor, but when I use it with a webplayer, the screenshot is stored correctly but then the viewer is flickering (sea attached image).
I have tried several things to release the RenderTexture but without success.
I have this problem only on Mac with Safari; I have no problems on WindowsXP with Firefox.
I am using Unity Pro.
function MakeScreenshot () {
var screenShotURL= “http://localhost:8888/image.php”;
screenshotCamera = Camera.main;
// We should only read the screen after all rendering is complete
yield WaitForEndOfFrame();
var l_width = Screen.width;
var l_height = Screen.height;
var rw : int = l_width * 2;
var rh : int = l_height * 2;
//All rendering goes into the active RenderTexture (active class property).
//If the active RenderTexture is null everything is rendered to the main window.
var rendert : RenderTexture;
rendert = RenderTexture.GetTemporary (rw, rh, 24);
RenderTexture.active = rendert;
screenshotCamera.targetTexture = rendert;
var tex = new Texture2D( rw, rh, TextureFormat.RGB24, false );
screenshotCamera.Render();
tex.ReadPixels( Rect(0, 0, rw, rh), 0, 0 );
tex.Apply();
// Encode texture into PNG
var bytes = tex.EncodeToPNG();
Destroy( tex );
// Create a Web Form
var form = new WWWForm();
form.AddField(“frameCount”, Time.frameCount.ToString());
var imageName=“”;
imageName=“screenShot.png”;
form.AddBinaryData(“image”, bytes, imageName, “image/png”);
// Upload to a cgi script
var w = WWW(screenShotURL, form);
yield w;
if (w.error != null)
print(w.error);
else {
Debug.Log (w.data);
print(“Finished Uploading Screenshot” + screenShotURL);
}
RenderTexture.ReleaseTemporary(rendert);
rendert = null;
screenshotCamera.targetTexture = null;
}