Beispiel #1
0
    void LateUpdate()
    {
        if (snapshot)
        {
            //Update();
            print_frames_rot.SetActive(false);
            editorCanvas.SetActive(false);
            renderCanvas.SetActive(true);
            exportCamera.SetActive(true);
            exportCameraCamera.orthographicSize = mapCameraCamera.orthographicSize;
            canvas.renderMode    = RenderMode.ScreenSpaceCamera;
            canvas.worldCamera   = exportCameraCamera;
            canvas.planeDistance = 1;



            int resWidth  = 1;
            int resHeight = 1;
            switch (renderOrientation)
            {
            case RenderOrientation.Portrait:
                resWidth  = 3508;
                resHeight = 4960;     // 4K A3 proportions, will be fine for print
                break;

            case RenderOrientation.Landscape:
                resWidth  = 4960;
                resHeight = 3508;     // 4K A3 proportions, will be fine for print
                break;
            }

            RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
            exportCameraCamera.targetTexture = rt;
            Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
            exportCameraCamera.Render();
            RenderTexture.active = rt;
            screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
            exportCameraCamera.targetTexture = null;
            RenderTexture.active             = null; // JC: added to avoid errors
            Destroy(rt);
            byte[] bytes     = screenShot.EncodeToPNG();
            byte[] ppi_bytes = B83.Image.PNGTools.ChangePPI(bytes, 300F, 300F); // upres to 300dpi

            dataIO.DownloadPrint(ppi_bytes);
            snapshot = false;
            exportCamera.SetActive(false);

            canvas.renderMode  = RenderMode.ScreenSpaceOverlay;
            canvas.worldCamera = null;

            renderCanvas.SetActive(false);
            editorCanvas.SetActive(true);
            print_frames_rot.SetActive(true);
        }
    }