美文网首页
不可保存的图片如何保存

不可保存的图片如何保存

作者: 最怕认真 | 来源:发表于2023-07-30 16:16 被阅读0次
        private Texture2D CopyT2DToWrite(Texture source)
        {
            // 先把Texture2D转成临时的RenderTexture
            RenderTexture renderTex = RenderTexture.GetTemporary(
                        source.width,
                        source.height,
                        0,
                        RenderTextureFormat.Default,
                        RenderTextureReadWrite.Linear);
            Graphics.Blit(source, renderTex);
            RenderTexture previous = RenderTexture.active;
            RenderTexture.active = renderTex;
            // 复制进新的Texture2D
            Texture2D readableText = new Texture2D(source.width, source.height);
            readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0);
            readableText.Apply();
            // 恢复_释放 RenderTexture
            RenderTexture.active = previous;
            RenderTexture.ReleaseTemporary(renderTex);
            return readableText;
        }
    

    相关文章

      网友评论

          本文标题:不可保存的图片如何保存

          本文链接:https://www.haomeiwen.com/subject/iaespdtx.html