- Home /
save the screenshot taken in game into android device's memory
Please I need help with this i have been able to take a screenshot i just need to save it into a folder of the android device(gallery documents..anyone).I have researched this but can't seem to find a working solution.Would really appreciate any help i can get with this. My current code is pasted below
import System.IO;
var explosion:GameObject[];
var dec:GUITexture;
var levelToLoad:String;
// increment our filename
private var count:int = 0;
/**
* Test key
*/
function Update()
{
}
//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.persistentDataPath + "/../MyTree-" + count + ".jpg", encoder.GetBytes());
yield WaitForSeconds(1);
//play sound here
//System.Diagnostics.Process.Start("mspaint.exe","MyTree-" + count + ".jpg");
count++;
guiTexture.enabled=true;
dec.guiTexture.enabled=true;;
Application.LoadLevel(levelToLoad);
}
function OnMouseDown(){
Destroy(GameObject.FindWithTag("chickens"));
Destroy(GameObject.FindWithTag("pal"));
guiTexture.enabled=false;
dec.guiTexture.enabled=false;
Instantiate(explosion[Random.Range(0,explosion.Length)]);;
yield WaitForSeconds(2);
ScreenshotEncode();
}
either will do so long i can save into a folder on the device
You can use this plugin For screenshots http://u3d.as/86U If you want to download and save - http://u3d.as/9Ee
Answer by flamy · Dec 03, 2013 at 11:39 AM
See the example from this link, This exactly does what you want.
It captures screen shot and saves in a location.
http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.EncodeToPNG.html
Instead of uploading link the above link save the file to datapath or persistent datapath.
// For testing purposes, also write to a file in the project folder
// File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png", bytes);
these lines would be commented in the example, replace with your required path strings.
Okay,after much research i have solved it using this
Application.CaptureScreenshot( "../../../../DCI$$anonymous$$/Camera/screenshot+count+.png");
Now this is the important part For this to work on Android, Write Access needs to be set to "External (SDCard)" in the Player Settings.Player Settings->Android->Other settings
I have set a count variable so that each time the player takes a screenshot the count incrases like screeshot1,screenshot2 etc but now the output is just screenshot+count+.png..how do i resolve this?
lol... you should have set double quotes there also... Application.CaptureScreenshot( "../../../../DCI$$anonymous$$/Camera/screenshot" +count+ ".png"); right?