How do I write an Texture2D image to disk on WSA App ?

Hi Folks,

I have been trying to write an image(Texture2D) on a new file on disk on WSA Platform.

By following the Microsoft’s documentation just as an sample and using a Plugin for File Picker I have been able to save a text file and also been able to write some text into it.

That works fine.
Now my main target is to write an image on a file (either a new file or an already existing one)

fileData = screenShot.EncodeToPNG();
    Windows.Storage.StorageFolder storageFolder = Windows.Storage.KnownFolders.PicturesLibrary;
            string byteConvertedtoSting = fileData.ToString();
            Windows.Storage.StorageFile sampleFile = await storageFolder.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.ReplaceExisting);
            Windows.Storage.StorageFile sampleFile1 = await storageFolder.GetFileAsync(fileName);
            var buffer = Windows.Security.Cryptography.CryptographicBuffer.CreateFromByteArray(fileData);
            await Windows.Storage.FileIO.WriteBufferAsync(sampleFile1, buffer);

By using this code I am able to create a .png file on disk, but unable to writes the Image bytes on the file. The file always shows the size of 0kb , as its simply empty.

Am I missing something in this or is ther any other way to do this ?

not 100% sure but it looks to me like you are trying to write data as a string and thats not going to work. Strings are a series of characters and behind the scene they terminate at the first 0 (null). You cant convert a BYTE series of data to characters so you must write them to the file as a series (blocks) of BYTEs