当前位置:   article > 正文

Unity 通过代码实现Texture2D可读写_unity texture2d 读写

unity texture2d 读写

  1. private Texture2D ConvertTexture(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. }

  1. private Texture2D ConvertTexture(Texture2D source)
  2. {
  3. byte[] pix = source.GetRawTextureData();
  4. Texture2D readableText = new Texture2D(source.width, source.height, source.format, false);
  5. readableText.LoadRawTextureData(pix);
  6. readableText.Apply();
  7. return readableText;
  8. }

参考:如何通过脚本使Texture2D可读_桔子。。的博客-CSDN博客

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

闽ICP备14008679号