Copy array to struct array as fast as possible in C#

前端 未结 5 1869
逝去的感伤
逝去的感伤 2020-12-16 21:24

I am working with Unity 4.5, grabbing images as bytes arrays (each byte represent a channel, taking 4 bytes per pixel (rgba) and displaying them on a texture converting the

5条回答
  •  Happy的楠姐
    2020-12-16 22:11

    Using Parallel.For may give you a significant performance increase.

    img = new Color32[byteArray.Length / nChannels]; //nChannels being 4
    Parallel.For(0, img.Length, i =>
    {
        img[i].r = byteArray[i*nChannels];
        img[i].g = byteArray[i*nChannels+1];
        img[i].b = byteArray[i*nChannels+2];
        img[i].a = byteArray[i*nChannels+3];
    });
    

    Example on MSDN

提交回复
热议问题