void SaveImage(Texture saveTexture, string mask)
{
if (saveTexture != null)
{
RenderTexture currentActive = new RenderTexture((int)(saveTexture.width), (int)(saveTexture.height), 0, RenderTextureFormat.ARGB32);
Graphics.Blit(saveTexture, currentActive);
RenderTexture restoreActive = RenderTexture.active;
RenderTexture.active = currentActive;
Texture2D screenShot = new Texture2D((int)(currentActive.width), (int)(currentActive.height), TextureFormat.RGB24, false);
screenShot.ReadPixels(new Rect(0, 0, currentActive.width, currentActive.height), 0, 0);
byte[] bytes = screenShot.EncodeToPNG();
string filename = "D://SavePicPath//" + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + mask + ".png";
System.IO.File.WriteAllBytes(filename, bytes);
Texture2D.DestroyImmediate(screenShot);
screenShot = null;
RenderTexture.active = restoreActive;
}
else
Debug.Log("RenderTexture IS NULL!!!");
{
if (saveTexture != null)
{
RenderTexture currentActive = new RenderTexture((int)(saveTexture.width), (int)(saveTexture.height), 0, RenderTextureFormat.ARGB32);
Graphics.Blit(saveTexture, currentActive);
RenderTexture restoreActive = RenderTexture.active;
RenderTexture.active = currentActive;
Texture2D screenShot = new Texture2D((int)(currentActive.width), (int)(currentActive.height), TextureFormat.RGB24, false);
screenShot.ReadPixels(new Rect(0, 0, currentActive.width, currentActive.height), 0, 0);
byte[] bytes = screenShot.EncodeToPNG();
string filename = "D://SavePicPath//" + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + mask + ".png";
System.IO.File.WriteAllBytes(filename, bytes);
Texture2D.DestroyImmediate(screenShot);
screenShot = null;
RenderTexture.active = restoreActive;
}
else
Debug.Log("RenderTexture IS NULL!!!");
}
public RenderTexture cameraTextures = new RenderTexture;
cameraTextures = new RenderTexture(2560, 1280, 24, RenderTextureFormat.Default);
SaveImage(cameraTextures , "Unity");