public static IEnumerator CaptureToFileCoroutine(string fileName, int width, int height, TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG, int JPGQuality = 100, List <Camera> cameras = null, List <Canvas> canvas = null, ScreenshotTaker.CaptureMode captureMode = ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE, int antiAliasing = 8, bool captureGameUI = true, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB, bool recomputeAlphaMask = false) { InitScreenshotTaker(); yield return(CaptureToTextureCoroutine(width, height, cameras, canvas, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask)); // EXPORT if (TextureExporter.ExportToFile(m_ScreenshotTaker.m_Texture, fileName, fileFormat, JPGQuality)) { Debug.Log("Screenshot created : " + fileName); } else { Debug.LogError("Failed to create screenshot : " + fileName); } }
public static string ParseExtension(TextureExporter.ImageFileFormat format) { if (format == TextureExporter.ImageFileFormat.PNG) { return(".png"); } else { return(".jpg"); } }
/// <summary> /// Captures the scene with the specified width, height, using the mode RENDER_TO_TEXTURE. /// Screenspace Overlay Canvas can not be captured with this mode. /// The filename must be a valid full name. /// </summary> public static void CaptureCameras(string fileName, int width, int height, List <Camera> cameras, TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG, int JPGQuality = 100, int antiAliasing = 8, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB, bool recomputeAlphaMask = false) { Capture(fileName, width, height, fileFormat, JPGQuality, cameras, null, ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE, antiAliasing, false, colorFormat, recomputeAlphaMask); }
/// <summary> /// Captures the current screen at its current resolution, including UI. /// The filename must be a valid full name. /// </summary> public static void CaptureScreen(string fileName, TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG, int JPGQuality = 100, bool captureGameUI = true, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB, bool recomputeAlphaMask = false) { Vector2 size = GameViewController.GetCurrentGameViewSize(); Capture(fileName, (int)size.x, (int)size.y, fileFormat, JPGQuality, null, null, ScreenshotTaker.CaptureMode.FIXED_GAMEVIEW, 8, captureGameUI, colorFormat, recomputeAlphaMask); }
/// <summary> /// Captures the game. /// The filename must be a valid full name. /// </summary> public static void Capture(string fileName, int width, int height, TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG, int JPGQuality = 100, List <Camera> cameras = null, List <Canvas> canvas = null, ScreenshotTaker.CaptureMode captureMode = ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE, int antiAliasing = 8, bool captureGameUI = true, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB, bool recomputeAlphaMask = false) { InitScreenshotTaker(); m_ScreenshotTaker.StartCoroutine(CaptureCoroutine(fileName, width, height, fileFormat, JPGQuality, cameras, canvas, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask)); }
/// <summary> /// Returns the parsed screenshot filename using the symbols, extensions and special folders. /// </summary> public static string ParseFileName(string screenshotName, ScreenshotResolution resolution, DestinationFolder destination, string customPath, TextureExporter.ImageFileFormat format, bool overwriteFiles, System.DateTime time) { string filename = ""; #if UNITY_EDITOR || !UNITY_WEBGL // Destination Folder can not be parsed in webgl filename += ParsePath(destination, customPath); #endif // File name filename += ParseSymbols(screenshotName, resolution, time); // Get the file extension filename += ParseExtension(format); // Increment the file number if a file already exist if (!overwriteFiles) { return(PathUtils.PreventOverwrite(filename)); } return(filename); }
public static void ShareImage(Texture2D texture, string screenshotName, string title = "", string subject = "", string description = "", TextureExporter.ImageFileFormat imageFormat = TextureExporter.ImageFileFormat.PNG, int JPGQuality = 70) { #if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID) string format = (imageFormat == TextureExporter.ImageFileFormat.JPG) ? "jpeg" : "png"; string filename = screenshotName + "." + format; // On iOS and Android share using Native Share var nativeShare = new NativeShare(); nativeShare.AddFile(texture, filename); nativeShare.SetTitle(title); nativeShare.SetSubject(subject); nativeShare.SetText(description); nativeShare.Share(); #elif !UNITY_EDITOR && UNITY_WEBGL // On WebGL share using custom share plugin // Convert texture to bytes byte[] bytes = null; if (imageFormat == TextureExporter.ImageFileFormat.JPG) { bytes = texture.EncodeToJPG(JPGQuality); } else { bytes = texture.EncodeToPNG(); } // Try sharing try { string format = (imageFormat == TextureExporter.ImageFileFormat.JPG) ? "jpeg" : "png"; WebGLUtils.ShareImage(bytes, screenshotName, format); } catch { Debug.LogError("Failed to share image."); } #else Debug.LogError("Share not supported on this platform."); #endif }
public static IEnumerator CaptureCoroutine(string fileName, int width, int height, TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG, int JPGQuality = 100, List <Camera> cameras = null, List <Canvas> canvas = null, ScreenshotTaker.CaptureMode captureMode = ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE, int antiAliasing = 8, bool captureGameUI = true, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB, bool recomputeAlphaMask = false) { // Create resolution item ScreenshotResolution captureResolution = new ScreenshotResolution(); captureResolution.m_Width = width; captureResolution.m_Height = height; captureResolution.m_FileName = fileName; // Create camera items List <ScreenshotCamera> screenshotCameras = new List <ScreenshotCamera> (); if (cameras != null) { foreach (Camera camera in cameras) { ScreenshotCamera scamera = new ScreenshotCamera(camera); screenshotCameras.Add(scamera); } } // Create the overlays items List <ScreenshotOverlay> screenshotCanvas = new List <ScreenshotOverlay> (); if (canvas != null) { foreach (Canvas c in canvas) { ScreenshotOverlay scanvas = new ScreenshotOverlay(c); screenshotCanvas.Add(scanvas); } } // Capture yield return(m_ScreenshotTaker.StartCoroutine(m_ScreenshotTaker.CaptureAllCoroutine(new List <ScreenshotResolution> { captureResolution }, screenshotCameras, screenshotCanvas, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask))); // EXPORT if (TextureExporter.ExportToFile(captureResolution.m_Texture, fileName, fileFormat, JPGQuality)) { Debug.Log("Screenshot created : " + fileName); } else { Debug.LogError("Failed to create : " + fileName); } }