ローカルエリアのスクリーンショットでの統一Texture2D.ReadPixelsは、RenderTextureの範囲外のReadPixelsを解決します。問題



Unity Any Local Area Screenshot Texture2d



エラーメッセージ:[d3d11] RenderTextureの範囲外の読み取りピクセルを(1920、1080)から読み取り(7000、340、8000、740)しようとしています!

問題の量、またはTexture2D.ReadPixelsパラメーター:



純粋に手動のデバッグ予測、テストは正しいです:

IEnumerator getScreenTexture(RectTransform rectT) { yield return new WaitForEndOfFrame() Texture2D t = new Texture2D ((int) rectT.rect.width, (int) rectT.rect.height, TextureFormat.RGB24, true) // need to correctly set the picture format to save 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) t.ReadPixels (position, 0, 0, true) // set according to the reading pixel region note the lower left corner as the origin is read t.Apply() // binary conversion byte[] byt = t.EncodeToPNG() File.WriteAllBytes(Application.dataPath + Time.time + '.png', byt) Debug.Log(Application.dataPath + Time.time + '.png') System.Diagnostics.Process.Start(Application.dataPath + Time.time + '.png') }