Unity中 保存图片到相册

xiaoxiao2021-02-28  111

使用插件 GalleryScreenshot

http://download.csdn.net/detail/chuan403082010/9922116

void OnEnable() { ScreenshotManager.ScreenshotFinishedSaving += ScreenshotSaved; ScreenshotManager.ImageFinishedSaving += ImageSaved; } void OnDisable() { ScreenshotManager.ScreenshotFinishedSaving -= ScreenshotSaved; ScreenshotManager.ImageFinishedSaving -= ImageSaved; } public void SaveImageClick() { Debug.Log ("baocun"); StartCoroutine("SaveAssetImage"); } public void OnTakeApictureBtnClick() { canvas.SetActive (false); StartCoroutine(ScreenshotManager.Save("MyScreenshot", "MyApp", true)); audio.Play (); } IEnumerator SaveAssetImage () { string path; foreach (Texture2D tex in textures) { if (tex.name.Contains (savePhotoName)) { #if UNITY_ANDROID path = Application.persistentDataPath + "/../../../../DCIM/" + "Camera" + "/" + tex.name + num + ".png"; #endif #if UNITY_IOS path = Application.persistentDataPath + "/"+ savePhotoName + num + ".jpg"; #endif num++; //tx.text = tex + "path:" +path ; byte[] bytes = tex.EncodeToPNG(); File.WriteAllBytes(path, bytes); yield return new WaitForEndOfFrame(); StartCoroutine(ScreenshotManager.SaveExisting(path, true)); } } } //拍照返回状态 void ScreenshotSaved() { canvas.SetActive (true); Debug.Log ("screenshot finished saving"); saved = true; } void ImageSaved() { //Debug.Log (texture.name + " finished saving"); saved2 = true; }

转载请注明原文地址: https://www.6miu.com/read-25398.html

最新回复(0)