Last active
August 29, 2015 14:02
-
-
Save tsubaki/eb11b8c3dd258d096c11 to your computer and use it in GitHub Desktop.
高画質なスクリーンショットの撮影
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
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