예제 #1
0
        static void TakeScreenShot()
        {
            try
            {
                if (Camera.main != null)
                {
                    var tex = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false);
                    tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
                    tex.Apply();

                    var scale   = 360.0f / (float)Screen.width;
                    var encoder = new JPGEncoder(tex, 25, scale);
                    var bytes   = encoder.GetBytes();

                    Texture2D.Destroy(tex);
                    AddData("screen", Encoding.ToBase64String(bytes));
                }
            }
            catch (System.Exception ex)
            {
                UnityEngine.Debug.LogWarning("Failed to create screenshot " + ex);
            }
        }
예제 #2
0
        public static byte[] ToJPG(Texture2D texture, float quality)
        {
            JPGEncoder encoder = new JPGEncoder(texture, quality);

            return(encoder.GetBytes());
        }