小编use*_*058的帖子

快速将Color32 []数组复制到byte []数组

会是怎样一个快速的方法来拷贝/转换一个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

c# struct copy marshalling unity-game-engine

4
推荐指数
1
解决办法
9051
查看次数

标签 统计

c# ×1

copy ×1

marshalling ×1

struct ×1

unity-game-engine ×1