如何将高(int16)值恢复为 rgb 形式?
How to get hight (int16) value back to rgb form?
我有 int16 * heights[width * height] 数组,它保存地形高度,我将它们直接从文件加载为 int16 *.
我需要将高度写入 bmp 文件。
考虑到它们首先来自 bmp 文件(rgb 格式),我如何将 int16 恢复为 rgb 格式?
谢谢。
您需要遍历数组并将每个 int16 转换为 RGB 值。如果 terrain
是你的数组
for (auto i=0; i<width * height; i++)
{
auto Color = terrain[i];
auto red = GetRValue16(color);
auto green = GetGValue16(color);
auto blue = GetBValue16(color);
}
关键是你对三个函数的定义GetXValue16
因为RGB通常是4字节的整数表示,即int32。另见 Extracting rgb color components from integer value
我有 int16 * heights[width * height] 数组,它保存地形高度,我将它们直接从文件加载为 int16 *.
我需要将高度写入 bmp 文件。
考虑到它们首先来自 bmp 文件(rgb 格式),我如何将 int16 恢复为 rgb 格式?
谢谢。
您需要遍历数组并将每个 int16 转换为 RGB 值。如果 terrain
是你的数组
for (auto i=0; i<width * height; i++)
{
auto Color = terrain[i];
auto red = GetRValue16(color);
auto green = GetGValue16(color);
auto blue = GetBValue16(color);
}
关键是你对三个函数的定义GetXValue16
因为RGB通常是4字节的整数表示,即int32。另见 Extracting rgb color components from integer value