Hey guys! Do you know about any good way to encode and save a PNG image to local HDD in a Standalone build? I know it isn’t possible in WebPlayer, but it hopefully is in Standalone.
– David
Hey guys! Do you know about any good way to encode and save a PNG image to local HDD in a Standalone build? I know it isn’t possible in WebPlayer, but it hopefully is in Standalone.
– David
Here you go:
import System.IO;
function SaveTextureToFile( texture: Texture2D,fileName)
{
var bytes=texture.EncodeToPNG();
var file = new File.Open(Application.dataPath + "/"+fileName,FileMode.Create);
var binary= new BinaryWriter(file);
binary.Write(bytes);
file.Close();
}
Call it using:
var myTexture: Texture2D;
function Startup()
{
SaveTextureToFile( myTexture,"picture.png");
}
Enjoy
** NOTE: The texture has to be readable. If its a texture that you’ve made should be ok but if you have imported then you need to make it readable.
string file_path = “PATH/FILENAME.PNG”;
byte filedata = texture2d.EncodeToPNG();
using (var fs = new FileStream(file_path, FileMode.Create, FileAccess.Write))
{
fs.Write(fileData, 0, fileData.Length);
}
Application.CaptureScreenshot(“Screenshot.png”);
thath save file named Screenshot.png in a folder where u have executable.
Best way is making function for multiple screenshot for don’t overwrite exiting shot.and i use thath on conditional function with a keyboard press.
thanking you