- Home /
how to release GPU RAM after taking a photo.
Hello how to free gpu ram after taking a photo. when reached ~1000 photos my computer is stuck because I used all the gpu ram. for now I am using the code below to create a photo:
IEnumerator takePhoto(string filename){
yield return new WaitForEndOfFrame();
// Debug.Log(gameObject.name + " Save Color Photo");
Texture2D screenImage = new Texture2D(Screen.width, Screen.height);
//Get Image from screen
screenImage.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
screenImage.Apply();
//KOKO
//Convert to png
byte[] imageBytes = screenImage.EncodeToPNG();
//Save image to file
System.IO.File.WriteAllBytes(filename + "_scene.png", imageBytes);
Comment
Answer by unity_J016ZU_VZQzYAg · Mar 22, 2019 at 04:20 PM
2DTexture is seen as gameobject in Unity, they are alive as long as the scene is alive or you destroy them via Destroy().
Your answer
Follow this Question
Related Questions
Scaling / Resizing an Image (Texture2D) 6 Answers
How do you crop a Texture2d 1 Answer
Image is not loading into Texture 0 Answers
Stop Texture2D Compression 0 Answers
Get multiple images from online server and download them to android app 1 Answer