Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/eb11b8c3dd258d096c11 to your computer and use it in GitHub Desktop.
Save tsubaki/eb11b8c3dd258d096c11 to your computer and use it in GitHub Desktop.
高画質なスクリーンショットの撮影
using UnityEngine;
using System.Collections;
public class TakeShot : MonoBehaviour {
public float maxScale = 2048;
void OnGUI()
{
if( GUILayout.Button("take"))
{
var max = Mathf.Max(Screen.width, Screen.height);
int width = (int)(maxScale * Screen.width / max );
int height = (int)(maxScale * Screen.height / max);
var rt = RenderTexture.GetTemporary(width, height);
var tex = new Texture2D(width, height, TextureFormat.ARGB32, false, false);
camera.targetTexture = rt;
camera.Render();
RenderTexture.active = rt;
tex.ReadPixels( new Rect(0, 0, width, height), 0, 0);
tex.Apply();
camera.targetTexture = null;
RenderTexture.active = null;
System.IO.File.WriteAllBytes("image.jpg", tex.EncodeToPNG());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment