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

后端 未结 5 1279
滥情空心
滥情空心 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:43

    In addition to Guffa's excellent advice, I would suggest that you profile your code to see where it's taking the time. Be sure that when you're timing this, you are running in release mode without the debugger attached.

    I wouldn't be surprised if the call to DrawImage is taking up most of the time. You're scaling the image there, which can be pretty expensive. How large is the box that you're drawing the image to?

    Finally, although this won't affect performance, you should change your code to read:

    using (Graphics g = _box.CreateGraphics())
    {
        g.InterpolationMode = InterpolationMode.NearestNeighbor;
        g.DrawImage(bmp, 0, 0, _box.Width, _box.Height);
    }
    

    And get rid of the first and last lines in your example.

提交回复
热议问题