我試圖將截屏保存到我的設備的圖像庫。 它工作正常,但不會顯示在畫廊中。Unity將圖像保存到圖庫android/ios
這是我做的
selfie= new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
selfie.ReadPixels(new Rect(0, 0,Screen.width, Screen.height), 0, 0,false);
selfie.Apply();
byte[] bytes = selfie.EncodeToPNG();
string filename = "Screenshot.png";
fileLocation = Path.Combine(Application.persistentDataPath, filename);
File.WriteAllBytes(fileLocation, bytes);
string myFolderLocation = "/mnt/sdcard/DCIM/Camera/";
myScreenshotLocation = myFolderLocation + filename;
System.IO.File.Move(fileLocation, myScreenshotLocation);
它節省了正確的地方的形象。如果我在SD卡上查看它,它就在那裏。 但在畫廊它沒有出現。所以我在File.move之後試過,刷新了庫。
//REFRESHING THE ANDROID PHONE PHOTO GALLERY IS BEGUN
AndroidJavaClass classPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject objActivity = classPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass classUri = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject objIntent = new AndroidJavaObject("android.content.Intent", new object[2]{"android.intent.action.MEDIA_MOUNTED", classUri.CallStatic<AndroidJavaObject>("parse", "file://" + myScreenshotLocation)});
objActivity.Call ("sendBroadcast", objIntent);
//REFRESHING THE ANDROID PHONE PHOTO GALLERY IS COMPLETE
但是這沒有做什麼。 我正在使用最新的Unity版本5.3,它應該適用於所有的android和ios設備。任何想法如何讓這個工作,並顯示在畫廊的任何地方?
謝謝!