I want to save the preview screen of the camera.
I want to save it in png or PSD format.
How can I do it?
I want to save the preview screen of the camera.
I want to save it in png or PSD format.
How can I do it?
Hello,
I found this :
maybe useful ?
Kind regards
Hi, not sure I understand the purpose of the script you attached.
From my point of view, you can create a c# file SR_RenderCamera.cs. copy/paste the code :
using System.IO;
using UnityEngine;
public class SR_RenderCamera : MonoBehaviour {
public int FileCounter = 0;
private void LateUpdate()
{
if (Input.GetKeyDown(KeyCode.F9))
{
CamCapture();
}
}
void CamCapture()
{
Camera Cam = GetComponent<Camera>();
RenderTexture currentRT = RenderTexture.active;
RenderTexture.active = Cam.targetTexture;
Cam.Render();
Texture2D Image = new Texture2D(Cam.targetTexture.width, Cam.targetTexture.height);
Image.ReadPixels(new Rect(0, 0, Cam.targetTexture.width, Cam.targetTexture.height), 0, 0);
Image.Apply();
RenderTexture.active = currentRT;
var Bytes = Image.EncodeToPNG();
Destroy(Image);
debug.Log("Will write under: " + Application.dataPath + "/Backgrounds/");
File.WriteAllBytes(Application.dataPath + "/Backgrounds/" + FileCounter + ".png", Bytes);
FileCounter++;
}
}
Attach it to you camera gameObject, this should do the trick.
I added a debug.Log to show where the files will be written, I think you should ensure this folder exists (and eventually create it if it’s not the case)
Thank you for your reply!
I dragged and dropped the script onto the camera.
However, [Can`t add script] was displayed.
Seems you called your script camera. I suggest you have the same filename as the classname: SR_RenderCamera in our case. I’m afraid your screenshots doesn’t help a lot to investigate. Maybe show the console to check if you have any compilation errors. Scripts with compilations error cannot be attached indeed.
Edit: You have the warning on the filename not matching classname in your screenshot in fact
Thank you for your reply!
I understood that the name [camera] was out.
I changed the name to [photograph].
But,
I get the same error.
[SR_RenderCamera]
Reclassified and script names.
But I get the same error.