Unity saves the picture locally

		public void SaveTexture2Local(Texture2D tex, string savePath = "")
        {
    
    
            //保存本地          
            Byte[] bytes = tex.EncodeToPNG();
            SaveTexture2Local(bytes,savePath);
        }

        public void SaveTexture2Local(byte[] bytes, string savePath="")
        {
    
    
            string dpath = string.IsNullOrEmpty(savePath) == true ? Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/截图/" : savePath;
            if (Directory.Exists(dpath) == false)
            {
    
    
                Directory.CreateDirectory(dpath);
            }

            Debug.Log($"截图目录{
      
      dpath}");
            string fileName = $"{
      
      dpath}ScreenShot{
      
      System.DateTime.Now.Month}_{
      
      System.DateTime.Now.Day}_{
      
      System.DateTime.Now.Hour}_{
      
      System.DateTime.Now.Minute}_{
      
      System.DateTime.Now.Second}.png";
            File.WriteAllBytes(fileName, bytes);
        }

Guess you like

Origin blog.csdn.net/qq_26318597/article/details/130638175