public void Screenshot_And_Printing()
{
StartCoroutine(CaptureScreenshot2(new Rect(0, 0, 1920, 1080)));
}
IEnumerator CaptureScreenshot2(Rect rect)
{
yield return new WaitForEndOfFrame();
// 先創建一個的空紋理,大小可根據實現需要來設置
Texture2D screenShot = new Texture2D(1920, 1080, TextureFormat.RGB24, false);
// 讀取屏幕像素信息並存儲爲紋理數據,
screenShot.ReadPixels(rect, 0, 0);
screenShot.Apply();
byte[] bytes = screenShot.EncodeToPNG();
string filename = Application.streamingAssetsPath + "/Screenshot.png";
System.IO.File.WriteAllBytes(filename, bytes);
string path = Application.streamingAssetsPath + "/Screenshot.png";
System.Diagnostics.Process process = new System.Diagnostics.Process(); //系統進程
process.StartInfo.CreateNoWindow = false; //不顯示調用程序窗口
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;//
process.StartInfo.UseShellExecute = true; //採用操作系統自動識別模式
process.StartInfo.FileName = path; //要打印的文件路徑
process.StartInfo.Verb = "print"; //指定對圖片執行的動作,打印:print 打開:open …………
process.Start(); //開始打印
}