Texture to texture2D

Posted 81192

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Texture to texture2D相关的知识,希望对你有一定的参考价值。

    private void SaveRenderTextureToPNG(Texture inputTex, string file)
    {
        RenderTexture temp = RenderTexture.GetTemporary(inputTex.width, inputTex.height, 0, RenderTextureFormat.ARGB32);
        Graphics.Blit(inputTex, temp);
        Texture2D tex2D = GetRTPixels(temp);
        RenderTexture.ReleaseTemporary(temp);
        File.WriteAllBytes(file, tex2D.EncodeToPNG());
    }

    private Texture2D GetRTPixels(RenderTexture rt)
    {
        RenderTexture currentActiveRT = RenderTexture.active;
        RenderTexture.active = rt;
        Texture2D tex = new Texture2D(rt.width, rt.height);
        tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
        RenderTexture.active = currentActiveRT;
        return tex;
    }

 

以上是关于Texture to texture2D的主要内容,如果未能解决你的问题,请参考以下文章

优化片段着色器

我的OpenGL学习进阶之旅解决着色器运行报错:ERROR: 0:32: ‘texture2D‘ : type is for Vulkan api only

频繁更新 Texture2D 会导致进程崩溃 (UpdateSubresource)

[设置纹理时内存泄漏=新的Texture2D(…)

unity中让Texture2D显示在Image上的问题

texture2D