直接上代碼: using System.IO; [csharp] void Update () { if(Input.GetKeyDown(KeyCode.A)) { StartCoroutine(getScreenTexture()); //unity 自帶截屏,只能是截全屏 Application.CaptureScreenshot("shot.png"); } } public int capx=0; public int capy=0; public int capwidth=700; public int capheight=500; IEnumerator getScreenTexture() { yield return new WaitForEndOfFrame(); Texture2D t = new Texture2D(capwidth, capheight,TextureFormat.RGB24, true);//需要正確設置好圖片保存格式 t.ReadPixels(new Rect(capx,capy,capwidth,capheight), 0, 0, false);//按照設定區域讀取像素;注意是以左下角為原點讀取 t.Apply(); //二進制轉換 byte[] byt = t.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + Time.time + ".png", byt); }