- Home /
Capture a (screen shot) scene shot with alpha
hi i want to take a screen shot with transparent background i use this code but if my object was particles / additive it dosen't show them or if i use antialiasing .. code :
RenderTexture rt = new RenderTexture (resWidth, resHeight, 24);
Camera.main.camera.targetTexture = rt;
Texture2D screenShot = new Texture2D (resWidth, resHeight, TextureFormat.ARGB32, false);
Camera.main.camera.Render ();
RenderTexture.active = rt;
screenShot.ReadPixels (new Rect (0, 0, resWidth, resHeight), 0, 0);
Camera.main.camera.targetTexture = null;
RenderTexture.active = null;
Destroy (rt);
byte[] bytes = screenShot.EncodeToPNG ();
//string filename = ScreenShotName (resWidth, resHeight);
string filename = string.Format ("{0}/mypic/screen_{1}x{2}_{3}.png",
Application.dataPath, resWidth, resHeight, counter);
counter = counter + 1;
System.IO.File.WriteAllBytes (filename, bytes);
Answer by smallkot · May 02, 2015 at 08:00 PM
The property of the camera
Clear Flags = Depth only
Code:
public static Texture2D TakeScreenShot()
{
return Screenshot ();
}
static Texture2D Screenshot() {
int resWidth = Camera.main.pixelWidth;
int resHeight = Camera.main.pixelHeight;
Camera camera = Camera.main;
RenderTexture rt = new RenderTexture(resWidth, resHeight, 32);
camera.targetTexture = rt;
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.ARGB32, false);
camera.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
screenShot.Apply ();
camera.targetTexture = null;
RenderTexture.active = null; // JC: added to avoid errors
Destroy(rt);
return screenShot;
}
public static Texture2D SaveScreenshotToFile(string fileName)
{
Texture2D screenShot = Screenshot ();
byte[] bytes = screenShot.EncodeToPNG();
System.IO.File.WriteAllBytes(fileName, bytes);
return screenShot;
}
Answer by FirePlantGames · Dec 16, 2014 at 11:56 PM
I'm not sure this is possible since when you screen shot you basically just capture what the camera is rendering, so know, you could try converting a certain color to transparency after you save the file. How you would do that I have know idea though...
hi , we can do that like this asset: https://www.assetstore.unity3d.com/en/#!/content/509
Your answer
Follow this Question
Related Questions
How do I take a high quality screen shot from my scene view camera? 5 Answers
can we pre-rendered video with unity? 1 Answer
How to display a camera on the screen while displaying the Oculus Rift in direct mode ? 1 Answer
UI render doesn't sync with Camera movement 2 Answers
Close objects in scene view are cut 2 Answers