IEnumerator getScreenTexture(RectTransform rectT)
{
yield return new WaitForEndOfFrame();
Texture2D screenShot = new Texture2D((int)rectT.rect.width, (int)rectT.rect.height, TextureFormat.RGB24, true);
float x = rectT.localPosition.x + (Screen.width - rectT.rect.width) / 2;
float y = rectT.localPosition.y + (Screen.height - rectT.rect.height) / 2;
Rect position = new Rect(x, y, rectT.rect.width, rectT.rect.height);
screenShot.ReadPixels(position, 0, 0, true);//按照设定区域读取像素;注意是以左下角为原点读取
screenShot.Apply();
string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
string filePath = "";
filePath = Application.persistentDataPath + "/HeadFold";
string scrPathName = filePath + "/" + fileName;
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
//二进制转换
byte[] byt = screenShot.EncodeToPNG();
File.WriteAllBytes(scrPathName, byt);
System.Diagnostics.Process.Start(scrPathName);
}