我正在尝试将屏幕截图保存到设备的图库中.它工作正常,但它不会出现在画廊中.
这就是我的工作
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("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 ("parse", "file://" + myScreenshotLocation)}); objActivity.Call ("sendBroadcast", objIntent); //REFRESHING THE ANDROID PHONE PHOTO GALLERY IS COMPLETE
但这无济于事.我正在使用最新的Unity版本5.3,它应该适用于所有Android和ios设备.任何想法如何使这个工作,并出现在画廊的任何地方?
谢谢!