Skip to content

Instantly share code, notes, and snippets.

@cellfusion
Created March 26, 2014 06:51
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save cellfusion/9777976 to your computer and use it in GitHub Desktop.
Save cellfusion/9777976 to your computer and use it in GitHub Desktop.
Unity でスクリーンショットを撮って画像を表示
// 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