什么是一种快速的方法将
Color32[]
数组中的值复制/转换到 byte[]
缓冲区?
Color32
是 Unity 3D 中包含 4 个字节,分别为 R、G、B 和 A
的结构体。
我想要实现的是通过管道将 Unity 渲染的图像发送到另一个应用程序(Windows Forms
)。目前我正在使用以下代码:private static byte[] Color32ArrayToByteArray(Color32[] colors)
{
int length = 4 * colors.Length;
byte[] bytes = new byte[length];
IntPtr ptr = Marshal.AllocHGlobal(length);
Marshal.StructureToPtr(colors, ptr, true);
Marshal.Copy(ptr, bytes, 0, length);
Marshal.FreeHGlobal(ptr);
return bytes;
}
感谢您,对 StackOverflow 我还不太熟悉,抱歉给您添麻烦。
马林斯库·亚历山德鲁