[DllImport (" __Internal ")]
Private static extern void _SavePhoto (string readAddr);
Public void Stt ()
{
//get the system time and name the photo name
System. A DateTime now=System. A DateTime. Now;
String times=now. The ToString ();
Times=times. The Trim ();
Times=times. Replace ("/", "-");
The string filename="Screenshot" + times + "PNG";
String Path_save;
//determine whether for IOS
If (Application) platform==RuntimePlatform) IPhonePlayer)
{
//capture screen
Texture2D texture=new Texture2D (Screen. The width, the Screen height, TextureFormat. RGB24, false);
Texture. ReadPixels (new the Rect (0, 0, Screen width, Screen, height), 0, 0).
Texture. The Apply ();
//to a byte array
Byte [] bytes=texture. EncodeToPNG ();
String destination=Application. PersistentDataPath;
Path_save=destination + "/" + filename;
//save picture
File. WriteAllBytes (Path_save, bytes);
Var readAddr=Path_save;
_SavePhoto (readAddr);
}
}
I write so in unity, button click
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
In Xcode added two scripts below
Take photos in the album after check, all remaining black images, is why? Good pain
CodePudding user response:
Screenshots of the method in coroutines