Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Set screensize for screenshot

$
0
0
So i found this code that takes screenshots of my game view works nice just that it captures the entire screen but i would want for it to capture just the centre of the screen which is where the real action is going on.Can anybody take a look at this script and give me some pointers on what to do. thanks. Here's the script import System.IO; // increment our filename private var count:int = 0; /** * Test key */ function Update() { if(Input.GetKeyDown("e")) ScreenshotEncode(); } /** * Take the screen buffer and spit out a JPG */ function ScreenshotEncode() { // wait for graphics to render yield WaitForEndOfFrame(); // create a texture to pass to encoding var texture:Texture2D = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false); // put buffer into texture texture.ReadPixels(Rect(0.0, 0.0, Screen.width, Screen.height), 0.0, 0.0); texture.Apply(); // split the process up--ReadPixels() and the GetPixels() call inside of the encoder are both pretty heavy yield; // create our encoder for this texture var encoder:JPGEncoder = new JPGEncoder(texture, 75.0); // encoder is threaded; wait for it to finish while(!encoder.isDone) yield; // save our test image (could also upload to WWW) File.WriteAllBytes(Application.dataPath + "/../testscreen-" + count + ".jpg", encoder.GetBytes()); } function OnGUI(){ if(GUI.Button(new Rect(10,10,100,30), "print")) { System.Diagnostics.Process.Start("mspaint.exe","testscreen-" + count + ".jpg"); count++; } }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>