会是怎样一个快速的方法来拷贝/转换一个array的Color32[]值的byte[]缓冲?
Color32是Unity 3D中包含的结构4 bytes, R, G, B and A respectively。我要完成的工作是将渲染的图像从整体通过管道发送到另一个应用程序(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;
}
Run Code Online (Sandbox Code Playgroud)
谢谢,抱歉,我是StackOverflow的新手。Marinescu Alexandru