public void paiZhao() //拍照
{
StartCoroutine(UploadPNG());
}
IEnumerator UploadPNG()
{
yield return new WaitForEndOfFrame();
int width = Screen.width;
int height = Screen.height;
Texture2D tex =
new Texture2D(width,
1250, TextureFormat.RGB24,
false);
tex.ReadPixels(
new Rect(
0,
315, width,
1250),
0,
0);
tex.Apply();
byte[] bytes = tex.EncodeToPNG();
Destroy(tex);
File.WriteAllBytes(Application.streamingAssetsPath +
"/onMobileSavedScreen.png", bytes);
}
上面是一种拍照的方式,下面再介绍一种更加简单的截屏方式:
FR: 徐海涛(Hunk Xu)