7#if !UNITY_EDITOR && UNITY_IOS
8 [System.Runtime.InteropServices.DllImport(
"__Internal" )]
9 private static extern void SaveImageToAlbum(
string path);
12 public string GalleryPath {
get;
private set; } =
string.Empty;
16 if (Application.platform == RuntimePlatform.Android) SetGalleryPath();
19 private void SetGalleryPath()
21 if (Application.platform == RuntimePlatform.Android && Application.platform == RuntimePlatform.Android)
23 var androidJavaClass =
new AndroidJavaClass(
"com.ToolBar.EasyWebCam.EasyWebCam");
24 androidJavaClass.CallStatic(
"getGalleryPath", gameObject.name);
32 private void receiveGalleryPath(
string androidPath)
40 if (Application.platform == RuntimePlatform.Android)
42 var androidJavaClass =
new AndroidJavaClass(
"com.ToolBar.EasyWebCam.EasyWebCam");
43 androidJavaClass.CallStatic(
"Refresh", path);
49#if (!UNITY_WEBPLAYER) && (!UNITY_WEBGL)
50 var bytes = qrCode.EncodeToJPG();
51 if (Application.platform == RuntimePlatform.Android)
53 var mediactr = FindObjectOfType<GalleryController>();
56 var aPath = mediactr.GalleryPath;
57 if (!
string.IsNullOrEmpty(aPath))
59 aPath = Path.Combine(aPath,
"QRCode_" + DateTime.Now.ToFileTime() +
".jpg");
62 File.WriteAllBytes(aPath, bytes);
63 Debug.Log(
"Saved : " + aPath);
69 mediactr.Refresh(aPath);
73 Debug.Log(
"Saved Code image Failed !");
77 else if (Application.platform == RuntimePlatform.IPhonePlayer)
79 var iPath = Application.persistentDataPath;
80 iPath = Path.Combine(iPath,
"QRCode" + DateTime.Now.ToFileTime() +
".jpg");
83 File.WriteAllBytes(iPath, bytes);
84 Debug.Log(
"Saved : " + iPath);
88 Debug.Log(
"Saved Code image Failed !");
91#if !UNITY_EDITOR && UNITY_IOS
92 SaveImageToAlbum( iPath );
93 Debug.Log(
"Saving to Pictures: " + Path.GetFileName( iPath ) );
96 else if (Application.platform == RuntimePlatform.WindowsPlayer
97 || Application.platform == RuntimePlatform.OSXPlayer
98 || Application.platform == RuntimePlatform.LinuxPlayer
99 || Application.platform == RuntimePlatform.OSXEditor
100 || Application.platform == RuntimePlatform.WindowsEditor)
102 var text = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
103 text = Path.Combine(text,
"QRCode" + DateTime.Now.ToFileTime() +
".jpg");
106 File.WriteAllBytes(text, bytes);
107 Debug.Log(
"Saved : " + text);
void Refresh(string path)
static void SaveImageToGallery(Texture2D qrCode)