[DllImport("__Internal")]
private static extern void _SavePhoto(string readAddr);
public void Stt()
{
//獲取系統時間并命名相片名
System.DateTime now = System.DateTime.Now;
string times = now.ToString();
times = times.Trim();
times = times.Replace("/", "-");
string filename = "Screenshot" + times + ".png";
string Path_save;
//判斷是否為IOS平臺
if (Application.platform == RuntimePlatform.IPhonePlayer)
{
//截取螢屏
Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
texture.Apply();
//轉為位元組陣列
byte[] bytes = texture.EncodeToPNG();
string destination = Application.persistentDataPath;
Path_save = destination + "/" + filename;
//存圖片
File.WriteAllBytes(Path_save, bytes);
var readAddr = Path_save;
_SavePhoto(readAddr);
}
}
我在unity里是這樣寫的,做成按鈕的click
————————————————————————————————————————
在Xcode里加了下面兩個腳本


拍照后在相冊中查看,全是存的黑色圖片,是為啥啊?好痛苦
uj5u.com熱心網友回復:
截圖的方法在協程里轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/247792.html
標籤:游戲開發
