快速将color []转换为byte []

问题描述 投票:0回答:1

Fast copy of Color32[] array to byte[] array

我已经看到,安静的类似问题。

但是我想将color []数组转换为byte []

private byte[] color2ByteArray(Color[] colors)
{
    int len = colors.Length;

    byte[] result = new byte[len * 3];

    int index = 0;

    for (int i = 0; i < len; i++)
    {
        result[index++] = (byte)(colors[i].r * 255);

        result[index++] = (byte)(colors[i].g * 255);

        result[index++] = (byte)(colors[i].b * 255);
    }

    return result;
}

要获得正确的颜色值并转换byte []数组。我必须将颜色乘以255。

我看过很多有关Marshal.copy的帖子

但是我不知道如何更改它以使其更快

我已经看过Color32 []数组的快速复制到byte []数组,安静的类似问题。但是我想将color []数组转换为byte []私有byte [] color2ByteArray(Color [] colors){int len = ...

c# colors byte marshalling
1个回答
0
投票

您可以像这样使用ToArgb Color方法:

© www.soinside.com 2019 - 2024. All rights reserved.