zoukankan      html  css  js  c++  java
  • Unity 截图

    class CaptureScreen : Editor
        {
            [MenuItem("Tool/CaptureScreen")]
            public static void DoAction()
            {
                Camera camera = Camera.main;
                camera.clearFlags = CameraClearFlags.Depth;
    
                //--------------截图的精细度跟这个尺寸有关系,越大,细节越多,另外一些看不见的物件,可能是lod的问题--------------
                int width = 1960*6;
                int height = 1960*6;
                //--------------------------------
                string path = Application.persistentDataPath + "/capture/screen_"+width+"_"+height+".png";
    
                RenderTexture rt = new RenderTexture(width, height, 0);
                camera.targetTexture = rt;
                camera.Render();
    
                RenderTexture.active = rt;
                Texture2D texture2D = new Texture2D(width, height, TextureFormat.RGB24, false);
                texture2D.ReadPixels(new Rect(0, 0, width, height), 0, 0, false);
                texture2D.Apply();
    
                byte[] data = texture2D.EncodeToPNG();
    
                string directoryPath = Path.GetDirectoryName(path);
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }
    
                File.WriteAllBytes(path, data);
    
                camera.targetTexture = null;
                RenderTexture.active = null;
                GameObject.DestroyImmediate(rt);
                data = null;
    
                Debug.Log("capture save to " + path);
    
            }
        }
  • 相关阅读:
    IDETalk
    servlet概述
    过滤器(Filter)
    ieda常用快捷键
    UUID
    JRebel 7.0.10 for intellij IDEA 2017.1
    BP神经网络(手写数字识别)
    遗传算法解决TSP问题
    [CODEVS1258]关路灯
    [NOIP2007]统计数字
  • 原文地址:https://www.cnblogs.com/jingxuan2583/p/14148164.html
Copyright © 2011-2022 走看看