- Home /
Question by
ergiomarxD · Mar 03, 2014 at 09:11 PM ·
c#androidscreenshot
Screenshot and save
I want to perform , then save it on phone and at the same time load it at the scene. This is for android phone, I've used this codes, but it only does screenshot and the application suddenly exit.
here is the code:
public int resWidth = 2550;
public int resHeight = 3300;
private bool takeHiResShot = false;
public static string ScreenShotName(int width, int height) {
return string.Format("{0}/screenshots/screen_{1}x{2}_{3}.png",
Application.dataPath,
width, height,
System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
}
public void TakeHiResShot() {
takeHiResShot = true;
}
void OnGUI(){
if (GUI.Button (new Rect (400, 10, 80, 50), "CAPTURE"))
takeHiResShot = true;
}
void LateUpdate() {
if (takeHiResShot) {
RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
camera.targetTexture = rt;
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
camera.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
camera.targetTexture = null;
RenderTexture.active = null; // JC: added to avoid errors
Destroy(rt);
byte[] bytes = screenShot.EncodeToPNG();
string filename = ScreenShotName(resWidth, resHeight);
System.IO.File.WriteAllBytes(filename, bytes);
Debug.Log(string.Format("Took screenshot to: {0}", filename));
takeHiResShot = false;
}
}
}`
Comment
Your answer
Follow this Question
Related Questions
screenshot 0 Answers
Weird issue with first-time effect call on Android 0 Answers
Multiple Cars not working 1 Answer
C++ windows DLL and Android? 1 Answer
Screenshot multiple 1 Answer