zhaoyang 3 年之前
父節點
當前提交
babb0fe6e6
共有 1 個文件被更改,包括 23 次插入4 次删除
  1. 23 4
      GameClient/Assets/Game/HotUpdate/Views/DressUp/PhotographSaveView.cs

+ 23 - 4
GameClient/Assets/Game/HotUpdate/Views/DressUp/PhotographSaveView.cs

@@ -1,3 +1,4 @@
+using System;
 using System.Collections;
 using System.IO;
 using FairyGUI;
@@ -40,12 +41,20 @@ namespace GFGGame
 
 #if UNITY_ANDROID
 
-            path = Application.persistentDataPath.IndexOf("Android") > 0 ? path.Substring(0, Application.persistentDataPath.IndexOf("Android")) + "DCIM/Camera/万世镜" : path + "/Pictures/万世镜";
+            path = Application.persistentDataPath.IndexOf("Android") > 0 ? path.Substring(0, Application.persistentDataPath.IndexOf("Android")) + "Pictures/万世镜" : path + "/Pictures/万世镜";
 #endif
             //判断目录是否存在,不存在则会创建目录
             if (!Directory.Exists(path))
             {
-                Directory.CreateDirectory(path);
+                try
+                {
+                    Directory.CreateDirectory(path);
+                }
+                catch (Exception exception)
+                {
+                    throw new Exception("创建文件夹失败, error:" + exception.Message);
+
+                }
             }
             string fileName = DateUtils.Instance.GetCurTime() + ".png";
             path = path + "/" + fileName;
@@ -53,9 +62,19 @@ namespace GFGGame
             Debug.Log("文件路径:" + path);
             Texture2D tex = this.viewData as Texture2D;
             byte[] bytes = tex.EncodeToPNG();//将纹理数据,转化成一个png图片
-
+            try
+            {
+                FileStream newFs = new FileStream(path, FileMode.Create, FileAccess.Write);
+                newFs.Write(bytes, 0, bytes.Length);
+                newFs.Close();
+                newFs.Dispose();
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("保存失败, error:" + ex.Message);
+            }
             // string path = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("Android"));
-            File.WriteAllBytes(path, bytes);
+            // File.WriteAllBytes(path, bytes);
             Timers.inst.StartCoroutine(GetSaveState(path));// ();
         }
         private IEnumerator GetSaveState(string path)