using System; using System.IO; using ET; using UnityEngine; namespace GFGGame { public class PoemPhotoDataManager : SingletonBase { /// /// 将照片保存到本地 /// public void SavePicturoToLocal(Texture2D tex) { string path = Application.persistentDataPath + "/Pictures/WanshiJing/"; //判断目录是否存在,不存在则会创建目录 if (!Directory.Exists(path)) { try { Directory.CreateDirectory(path); } catch (Exception exception) { throw new Exception("创建文件夹失败, error:" + exception.Message); } } string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg"; var filePath = path + fileName; byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片 File.WriteAllBytes(filePath, bytes); UpdateSystemPhoto(filePath); } //调用iOS或Android原生方法保存图片后更新相册. private void UpdateSystemPhoto(string filePath) { #if UNITY_ANDROID AndroidJavaObject androidJavaObject = new AndroidJavaObject("com.gfg.gfglibrary.SaveImage"); //设置成我们aar库中的签名+类名 androidJavaObject.Call("scanFile", filePath, "已保存至相册"); //这里我们可以设置保存成功弹窗内容 #endif } } }