Texture2D读取像素并保存
ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.
调用ReadPixels从系统框架缓冲区读取像素,而不是在画框内。
唉,又又遇到这个问题了,之前没觉得这个会出什么问题,结果又出了,那就记录一下吧
!!!
IEnumerator SignatureSave()
{
yield return new WaitForEndOfFrame();
Texture texture = _paintCanvas.GetComponent<RawImage>().texture;
Texture2D texture2D = new Texture2D(texture.width,texture.height, TextureFormat.ARGB32, false);
texture2D.ReadPixels(new Rect(0,0,texture.width,texture.height),0,0);
texture2D.Apply();
File.WriteAllBytes(Application.streamingAssetsPath + "/Pics/" + DateTime.Now.Ticks + ".png", texture2D.EncodeToPNG());
StartCoroutine(WaitForNewRenderTexture());
}
很正常的一段代码,但是切记第一句等待此帧结束!!!