Hi guys, Hoping someone can point me in the right direction with this as i'm running out of ideas. I'm unable to take a screenshot or store it in a metro app. I've tried the normal Applicaiton.CaptureScreenshot code which results in: Code (csharp): about to send file over playerconnection C:/Projects/ProjectName/Export/ProjectName/bin/x86/Debug/AppX/Data/Test_1887.png with length 71053 Failed to store screen shot /edit/ Problem solved, i ended up trying ReadPixels (has some problem with this as well, where using a render texture didn't include OnGUI textures, and plain ReadPixels on a Texture2D resulted in black pixels). Turns out i didnt yield a frame before reading pixels. That being said, any idea why Application.CaptureScreenshot won't work?
So the code I'm using now to capture the screenshot is simply: Code (csharp): string filename = "Test_" + Random.Range(0, 9999) + ".png"; string fullpath = ""; yield return new WaitForEndOfFrame(); Texture2D tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); tex.name = "ScreenScrape"; tex.Apply(); byte[] bytes = tex.EncodeToPNG(); Destroy(tex); After I have the bytes, I'm using the data writer to write it to the pictures library: Code (csharp): private static async void _ByteArrayToBitmapImage(string fileName, byte[] byteArray) { //Find the pictures folder Windows.Storage.StorageFolder picturesFolder = Windows.Storage.KnownFolders.PicturesLibrary; var imageFile = await picturesFolder.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.ReplaceExisting); var fs = await imageFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite); var writer = new Windows.Storage.Streams.DataWriter(fs.GetOutputStreamAt(0)); writer.WriteBytes(byteArray); await writer.StoreAsync(); writer.DetachStream(); await fs.FlushAsync(); } Hope that all came through fine. I'm currently on my phone
You have to specify full path, where files can be saved, AppX/Data is readonly directory. Try using UnityEngine.Windows.Directory.tempraryfolder, and save screenshot there.