c# - 统一更改 Texture2D 格式
问题描述
我有一个Textured2D
加载的内容,其中表示ETC_RGB4
如何将其更改为另一种格式?说RGBA32
。基本上我想从 3 个通道切换到 4 个通道,从每个通道 4 位切换到每个通道 8 个。
谢谢
解决方案
您可以在运行时更改纹理格式。
1 .创建新的空Texture2D
并提供RGBA32
给TextureFormat
参数。RGBA32
这将创建一个具有格式的空纹理。
2 .用于Texture2D.GetPixels
获取ETC_RGB4
格式中的旧纹理的像素,然后用于Texture2D.SetPixels
将这些像素放入来自#1的新创建的纹理中。
3 .调用Texture2D.Apply
以应用更改。而已。
一个简单的扩展方法:
public static class TextureHelperClass
{
public static Texture2D ChangeFormat(this Texture2D oldTexture, TextureFormat newFormat)
{
//Create new empty Texture
Texture2D newTex = new Texture2D(2, 2, newFormat, false);
//Copy old texture pixels into new one
newTex.SetPixels(oldTexture.GetPixels());
//Apply
newTex.Apply();
return newTex;
}
}
用法:
public Texture2D theOldTextue;
// Update is called once per frame
void Start()
{
Texture2D RGBA32Texture = theOldTextue.ChangeFormat(TextureFormat.RGBA32);
}
推荐阅读
- privateid - 嵌入如何用于完全同态加密?
- security - Safari 和 SSL 证书有什么关系?
- python - 在python中创建图形后如何更改散点的轴限制
- html - 找不到“delete_task/{{todo.id}}”的反向。'delete_task/{{todo.id}}' 不是有效的视图函数或模式名称
- c++ - 如何在不指定模板变量的情况下访问 std::map 模板变量中的元素?
- javascript - 从数组创建对象的对象
- linux - 在终端输出 2 列到 1 上读取 pdf
- node.js - express 节点无法读取未定义的内容
- c++ - 使用 .find 函数在 C++ 中查找字符和另一个字符之间的大小
- javascript - 如何避免覆盖节点中现有的文件 json 对象