Texture转Texture2D

  private Texture2D TextureToTexture2D(Texture texture)
    {
        Texture2D texture2D = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false);
        RenderTexture currentRT = RenderTexture.active;
        RenderTexture renderTexture = RenderTexture.GetTemporary(texture.width, texture.height, 32);
        Graphics.Blit(texture, renderTexture);

        RenderTexture.active = renderTexture;
        texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
        texture2D.Apply();

        RenderTexture.active = currentRT;
        RenderTexture.ReleaseTemporary(renderTexture);

        return texture2D;
    }
 private Texture2D RenderTextureToTexture2D(RenderTexture texture)
    {
        RenderTexture RT = RenderTexture.active;
        RenderTexture.active = texture;
        Texture2D texture2D = new Texture2D(texture.width,texture.height);
        texture2D.ReadPixels(new Rect(0,0,texture2D.width,texture2D.height),0,0);
        return texture2D;
    }


 
原文地址:https://www.cnblogs.com/SevenPixels/p/10442158.html