1 Color32[]转为Byte[]字节数组

代码示例:

private static byte[] Color32ArrayToByteArray(Color32[] colors)
{
    if (colors == null || colors.Length == 0)
        return null;

    int lengthOfColor32 = Marshal.SizeOf(typeof(Color32));
    int length = lengthOfColor32 * colors.Length;
    byte[] bytes = new byte[length];

    GCHandle handle = default(GCHandle);
    try
    {
        handle = GCHandle.Alloc(colors, GCHandleType.Pinned);
        IntPtr ptr = handle.AddrOfPinnedObject();
        Marshal.Copy(ptr, bytes, 0, length);
    }
    finally
    {
        if (handle != default(GCHandle))
            handle.Free();
    }
    return bytes;
}

参考链接

当前分类随机文章推荐

全站随机文章推荐

关于本站站长 StubbornHuang
Unity – Color32[]转为byte[]字节数组-StubbornHuang Blog纵使晴明无雨色,入云深处亦沾衣。