gameview capture in realtime
hello i have a question in unity I am using unity 5.6.3 linux on pc (ubuntu) I want to capture the screen in the current game view in real time and save it as a jpg file. Can I add a script to my main camera to make it possible? thank you
i want to make jpg file in raltime examplly test0.jpg , test1.jpg , test2.jpg ...... test 9999.jpg
but this script made only test0.jpg file and continuously updated with the same filename
how can i fiw that?
code ->using System.Collections; using System.Collections.Generic; using UnityEngine;
public class capture : MonoBehaviour {
void Update(){ StartCoroutine("Rendering"); } IEnumerator Rendering () {
int count = 0;
yield return new WaitForEndOfFrame();
byte[] imgBytes;
string path = @"/home/haeyun/Desktop/screen/test"+ count;
count = count + 1 ;
Texture2D texture = new Texture2D(Screen.width , Screen.height , TextureFormat.RGB24 , false);
texture.ReadPixels(new Rect(0,0,Screen.width, Screen.height), 0 ,0, false);
texture.Apply ();
imgBytes = texture.EncodeToJPG();
DestroyImmediate(texture);
System.IO.File.WriteAllBytes(path + ".jpg" , imgBytes);
Debug.Log( path = " has been saved");
yield return new WaitForSecondsRealtime (5);
}
}
Answer by thibetanus · Sep 05, 2018 at 05:18 AM
i fix that using System.Collections; using System.Collections.Generic; using UnityEngine;
public class capture : MonoBehaviour {
float delay = 1.3f;
int count = 0 ;
void ScreenCapture (int width, int height , string path){
byte[] imgBytes = null;
Texture2D texture = new Texture2D(Screen.width , Screen.height , TextureFormat.RGB24 , false);
texture.ReadPixels(new Rect(0,0,Screen.width, Screen.height), 0 ,0, false);
texture.Apply ();
imgBytes = texture.EncodeToJPG();
System.IO.File.WriteAllBytes(path + ".jpg" , imgBytes);
Debug.Log( path + " has been saved");
}
void Update(){
StartCoroutine("Rendering");
}
IEnumerator Rendering () {
yield return new WaitForEndOfFrame();
string path = @"/home/haeyun/Desktop/screen/test"+ count;
ScreenCapture(Screen.width, Screen.height, path);
count ++;
yield return new WaitForSeconds(delay); // 이게 왜 처음에만 적용이 될까??????? 허어어어어어ㅓ,,,,
}
}
it saves real-time files , but that's too much how can i control that ?