- Home /
How to save screenshot in windows phone gallery using unity ?
I am trying to save the texture using the untiy Method of Application.CaptureScreenShot(); but it not save the screen shot to the windows phone camera roll or gallery.i have searched a lot of foroums for my problem but found nothing. :( Can anyone please solve this issue or suggest me any link. Thanks in advanced. :)
Have you checked the persistent data path ?
On mobile platforms the filename is appended to the persistent data path.
http://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
yes i can see the screenshots that are save in my local computer.but that are not save to the gallery or camera roll of windows phone.
I guess the gallery does not look for images in the persistent data path simply. Try to find how you can move the screenshot inside the standard images folder.
Answer by jijieciprian · Oct 06, 2016 at 02:18 PM
To save a screenshot in windows phone using unity need to do like this:
Use this directive #if NETFX_CORE to declare some code for windows phone :
StorageFolder picturesLibraryFolder = KnownFolders.PicturesLibrary //(picture library folder)
Write a method with two param (fileName and byte[] file (here is image encoded to png/jpg from texture2D when make capture)
--async YourNameMethod(string fileName, byte[] file)--
In body need to use a storage file where wou need to create a file in your picture library folder.
StorageFile storageFile = await picturesLibraryFolder.CreateFileAsync(fileName);
And finaly you need to write bytes
await FileIO.WriteBytesAsync(storageFile, file);
To be more easier:
#if NETFX_CORE
async void SaveYourScreenShotInPicturesLibrary(string fileName, byte[] file)
{
StorageFile storageFile = await picturesLibraryFolder.CreateFileAsync(fileName);
await FileIO.WriteBytesAsync(storageFile, file);
}
#endif
void MethodWhereYouCallSave(string fileName, byte[] file)
{
#if NETFX_CORE
SaveYourScreenShotInPicturesLibrary(fileName,file)
#endif
}
try like this and let me know :)
It won't work since it requires Windows.Storage library and C#6.0 support. While Unity is not officially support C#6.0 right now. And even with third-party plugin that allow support of C#6-7 - it still didn't work. $$anonymous$$ay be you know some other workaround for saving in Picture gallery on UWP ?
I tried something similar, and it didn't seem to work for me either.