Skip to content

Instantly share code, notes, and snippets.

@voxelbustersold
Last active January 4, 2019 07:50
Show Gist options
  • Save voxelbustersold/a8c603c7a4c9172ddb9c16b17ca023b9 to your computer and use it in GitHub Desktop.
Save voxelbustersold/a8c603c7a4c9172ddb9c16b17ca023b9 to your computer and use it in GitHub Desktop.
Save Texture2D to Persistent Path
// Required Namesapce for using Utitlity Functions
using VoxelBusters.InstagramKit.Common.Utility;
// You need pass a texture2D which is marked as Readable in its inspector and pass saveName with extension. Ex: photo.png or photo.jpg
void SaveImage(Texture2D image, string saveName)
{
byte[] data = null;
if (saveName.EndsWith("png"))
{
data = ImageConversion.EncodeToPNG(image);
}
else
{
data = ImageConversion.EncodeToJPG(image);
}
FileOperations.WriteAllBytes(Application.persistentDataPath + "/" + saveName, data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment