Version: 1.7
LanguageEnglish
  • C#

Gallery.SaveImage

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static void SaveImage(Action<string> gallerySaveCallback, Texture2D texture);

Parameters

gallerySaveCallback Callback which will be executed when save image finished.
texture Texture to be saved.

Description

Save a Texture2D to gallery.

using System.Collections;
using UnityEngine;
using UnityEngine.OpenHarmony;

public class SaveImagesScript : MonoBehaviour { void Start() { StartCoroutine(TakeScreenshot()); }

private IEnumerator TakeScreenshot() { yield return new WaitForEndOfFrame(); Texture2D screenshot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); screenshot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); screenshot.Apply(); Gallery.SaveImage((str) => { Debug.Log($"Save path : {str}.\n"); }, screenshot); } }