当前位置:   article > 正文

Unity Texture2D读取像素时出错问题_unity texture2d getpixels 取不到

unity texture2d getpixels 取不到

Texture2D在读取像素处理时,经常会出错,这个时候可以用如下函数先转换:

  1. public Texture2D DeCompress(Texture2D source)
  2. {
  3. RenderTexture renderTex = RenderTexture.GetTemporary(
  4. source.width,
  5. source.height,
  6. 0,
  7. RenderTextureFormat.Default,
  8. RenderTextureReadWrite.Linear);
  9. Graphics.Blit(source, renderTex);
  10. RenderTexture previous = RenderTexture.active;
  11. RenderTexture.active = renderTex;
  12. Texture2D readableText = new Texture2D(source.width, source.height);
  13. readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0);
  14. readableText.Apply();
  15. RenderTexture.active = previous;
  16. RenderTexture.ReleaseTemporary(renderTex);
  17. return readableText;
  18. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/766659
推荐阅读
相关标签
  

闽ICP备14008679号