C# LockBits perfomance (int[,] to byte[])

后端 未结 5 1293
滥情空心
滥情空心 2020-12-21 06:26
Graphics g;
using (var bmp = new Bitmap(_frame, _height, PixelFormat.Format24bppRgb))
{
    var data = bmp.LockBits(new Rectangle(0, 0, _frame, _height), ImageLockMo         


        
5条回答
  •  难免孤独
    2020-12-21 06:35

    Try this using unsafe code:

    byte* rp0;
    int* vp0;
    fixed (byte* rp1 = rgb)
    {
        rp0 = rp1;
        fixed (int* vp1 = _values)
        {
            vp0 = vp1;
            Parallel.For(0, _width, (i) =>
            {
                var val = (byte)vp0[i];
                rp0[i] = val;
                rp0[i + 1] = val;
                rp0[i + 2] = val;
            });
        }
    }
    

    Runs very fast for me

提交回复
热议问题