Now I need to implement saving images to my iOS device. I have seen many online examples using “ScreenCapture.CaptureScreenshot(filepach);” for screenshot capture, but what I need is to save the texture image prepared in Unity. Please ask me What do you need to do.
Hi @Vortexboy
there is a simple way to save textures to your device.
IEnumerator SaveTexture(Texture2D texture)
{
string fileName = "Photo";
string screenshotFilename;
string path;
string date = System.DateTime.Now.ToString("ddMMyyHHmmss");
screenshotFilename = fileName + "_" + date + ".png";
if (Application.platform == RuntimePlatform.Android)
{
string androidPath = "/../../../../DCIM/YourAppName/" + screenshotFilename;
path = Application.persistentDataPath + androidPath;
string pathonly = Path.GetDirectoryName(path);
if (!Directory.Exists(pathonly))
{
Directory.CreateDirectory(pathonly);
}
}
else if (Application.platform == RuntimePlatform.IPhonePlayer)
{
string iosPath = Application.persistentDataPath + "/" + screenshotFilename;
path = iosPath;
}
else
{
string otherPath = screenshotFilename;
path = otherPath;
}
byte[] bytes = texture.EncodeToJPG();
File.WriteAllBytes(path, bytes);
yield return new WaitForEndOfFrame();
}