本文主要是介绍Unity Texture2D读取像素时出错问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Texture2D在读取像素处理时,经常会出错,这个时候可以用如下函数先转换:
public Texture2D DeCompress(Texture2D source){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 readableText = new Texture2D(source.width, source.height);readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0);readableText.Apply();RenderTexture.active = previous;RenderTexture.ReleaseTemporary(renderTex);return readableText;}
这篇关于Unity Texture2D读取像素时出错问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!