結果呈現如下:
SCREEN SHOT : Unity 3D目前螢幕擷取方式有兩種
第一種 :
使用Unity 3D現成的Application.CaptureScreenshot("pic.png")函式來完成螢幕畫面的擷取,圖片儲存路徑預設為Application.persistentDataPath
第二種 :
使用ReadPixel的方式來完成螢幕畫面的擷取,程式碼如下:
public Camera mainCamera; IEnumerator ScreenCapture() { //在擷取畫面之前請等到所有的Camera都Render完 yield return new WaitForEndOfFrame(); Texture2D texture = new Texture2D((int)mainCamera.pixelWidth, (int)mainCamera.pixelHeight); //擷取全部畫面的資訊 texture.ReadPixels(new Rect(0, 0, (int)mainCamera.pixelWidth, (int)mainCamera.pixelHeight),0,0, false); texture.Apply(); }螢幕擷取後,儲存圖片:
void SaveTextureToFile(Texture2D texture, string fileName) { byte[] bytes = texture.EncodeToPNG(); string filePath = Application.dataPath + "/" + fileName + ".png"; using (FileStream fs = File.Open(filePath, FileMode.Create)) { BinaryWriter binary = new BinaryWriter(fs); binary.Write(bytes); } }程式碼參考自 -> http://www.iverv.com/2014/04/unityscreenshot.html
螢幕畫面擷取後儲存的路徑分類:
Application.dataPath
建議視窗開發中用的路徑:
windows: /Assets
IPone: Application/???/Name.app/Data
Android: /data/app/Name.apk
Application.persistentDataPath
Contains the path to a persistent data directory (Read Only).
平台中的公開目錄,文件持久性的保存不會因為應用程式更新或升級而刪除
windows: C:/Users/xxxx/AppData/LocalLow/CompanyName/ProductName
IPone: Application/???/Documents
Android: /data/data/Name/files
Application.streamingAssetsPath
專案目錄下面的 Assets/StreamingAssets
windows: /Assets/StreamingAssets
IPone: Application/???/Name.app/Data/Raw
Android: jar:file:///data/app/Name.apk/!/assets
Application.temporaryCachePath
Contains the path to a temporary data / cache directory (Read Only).
平台的快取儲存路徑
windows: C:/Users/xxxx/AppData/Local/Temp/CompanyName/ProductName
IPone: Application/???/Library/Caches
Android: /data/data/Name/cache
沒有留言:
張貼留言