Created
March 26, 2014 06:51
-
-
Save cellfusion/9777976 to your computer and use it in GitHub Desktop.
Unity でスクリーンショットを撮って画像を表示
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Screenshot を撮る | |
Application.CaptureScreenshot("screenshot.png"); | |
// プラットフォームごとに保存位置変わる? | |
string path = ""; | |
switch (Application.platform) { | |
case RuntimePlatform.IPhonePlayer: | |
path = Application.persistentDataPath + "/screenshot.png"; | |
break; | |
case RuntimePlatform.Android: | |
path = Application.persistentDataPath + "/screenshot.png"; | |
break; | |
default: | |
path = "screenshot.png"; | |
break; | |
} | |
Debug.Log("path:"+path); | |
// スクリーンショットの読み込み | |
byte[] image = File.ReadAllBytes(path); | |
// Texture2D を作成して読み込み | |
Texture2D tex = new Texture2D(0, 0); | |
tex.LoadImage(image); | |
// NGUI の UITexture に表示するとき | |
UITexture target = GameObject.Find("DebugTexture").GetComponent(); | |
target.mainTexture = tex; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment