来自TextureFormat.R16的一般说明
目前,这种纹理格式仅对运行时或本机代码插件有用,因为不支持这种格式的纹理导入。
注意不是所有显卡都支持所有纹理格式,请使用SystemInfo.SupportsTextureFormat查看。
如果您真的想使用R16 格式纹理,我没有直接的解决方案,除非以某种方式将数据序列化为byte[],例如使用Buffer.BlockCopy - 注意:根本不知道这会起作用!
ushort[] yourData = // wherever you get this from;
byte[] byteData = new byte[sizeof(ushort) * yourData.Length];
// On memory level copy the bytes from yourData into byteData
Buffer.BlockCopy(yourData, 0, byteData, 0, byteData.Length);
infraredTexture = new Texture2D(infraredFrame.Width, infraredFrame.Height, TextureFormat.R16, false);
infraredTexture.LoadRawTextureData(byteData);
infraredTexture.Apply();
再一次不知道它是否可以这样工作。
但是,我认为您可以在 Unity 中简单地“伪造”它。如果它仅用于显示纹理,您可以使用“普通”RGB24 纹理,只需将 16 位单通道数据映射为灰度 24 位 RGB 颜色,然后使用 Texture2D.SetPixels 应用它,例如
ushort[] yourData = // wherever you get this from;
var pixels = new Color[yourData.Length];
for(var i = 0; i < pixels.Length; i++)
{
// Map the 16-bit ushort value (0 to 65535) into a normal 8-bit float value (0 to 1)
var scale = (float)yourData[i] / ushort.MaxValue;
// Then simply use that scale value for all three channels R,G and B
// => grey scaled pixel colors
var pixel = new Color(scale, scale, scale);
pixels[i] = pixel;
}
infraredTexture = new Texture2D(infraredFrame.Width, infraredFrame.Height, TextureFormat.RGB24, false);
// Then rather use SetPixels to apply all these pixel colors to your texture
infraredTexture.SetPixels(pixels);
infraredTexture.Apply();