Created
September 10, 2024 07:29
-
-
Save unitycoder/35051efd864c07a63cc2d0b81873f49a to your computer and use it in GitHub Desktop.
Take Screenshot from Specific Display1 - n (camera)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://discussions.unity.com/t/multiple-camera-screenshots/481847/13 | |
public void Screenshot() | |
{ | |
foreach (GameObject go in GameObject.FindGameObjectsWithTag("picCam")) | |
{ | |
Camera cam = go.GetComponent<Camera>(); | |
resWidth = cam.pixelWidth; | |
resHeight = cam.pixelHeight; | |
RenderTexture rt = new RenderTexture(resWidth, resHeight, 24); | |
cam.targetTexture = rt; | |
cam.Render(); | |
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false); | |
RenderTexture.active = rt; | |
screenShot.ReadPixels(cam.pixelRect, 0, 0); | |
screenShot.Apply(); | |
byte[] bytes = screenShot.EncodeToPNG(); | |
string filename = ScreenShotName(resWidth, resHeight); | |
System.IO.File.WriteAllBytes(filename, bytes); | |
cam.targetTexture = null; | |
RenderTexture.active = null; | |
rt.Release(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment