【问题标题】:Unity create texture from TGAUnity 从 TGA 创建纹理
【发布时间】:2018-01-07 01:55:29
【问题描述】:

我尝试从 StreamingAsets 文件夹生成精灵,但在从 PNG 和 JPG 以外的格式创建纹理时遇到了困难。以下代码:

    byte[] bytes = File.ReadAllBytes (filepath);    // 256x256 .tga image file
    Texture2D texture = new Texture2D (1, 1);
    texture.LoadImage (bytes);

生成 8x8 纹理,即:

  • 错误地认为我的图像是 256x256,
  • 预期,因为 Texture2D.LoadImage 旨在处理 PNG 和 JPG。

那么如何从其他类型的图像创建纹理?

【问题讨论】:

  • LoadImage 只加载 jpg 或 png,是不是你得到了错误尺寸的图像,你是如何试验的。你试试 LoadRawTextureData 设置图片大小?

标签: c# arrays unity3d textures texture2d


【解决方案1】:

不支持 TGA 格式。您必须编写自己的包装器才能这样做,但其中许多包装器确实已经存在。请参阅TGALoader 类。使用起来非常简单。

Texture2D texture = TGALoader.LoadTGA(sfilepath);

您的 TGA 图像现在已加载到 texture 变量中。

【讨论】:

  • 哇!完成了! TGALoader 是很好的基础,尽管我必须更新脚本才能读取 RLE 压缩图像。
猜你喜欢
  • 1970-01-01
  • 2016-12-14
  • 1970-01-01
  • 2018-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-17
  • 2016-04-04
相关资源
最近更新 更多