图像绘制速度 [英] Image draw speed

查看:58
本文介绍了图像绘制速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款游戏,但目前我正在运行基准测试.

i am working on a game, but currently I am running benchmarks.

如果有人能帮助我解决这个问题,我将不胜感激.

If anyone can help me on this matter, I would greatly appreciate it.

我在做什么,当我点击开始按钮时,我在面板上触发了绘画事件,代码如下:

What I am doing, is I fire the paint event on a panel when I click the start button, with this code:

    private void startToolStripMenuItem_Click(object sender, EventArgs e)
    {
        try
        {
            pnlArea.Invalidate();

        }
        catch (Exception)
        {
            throw;
        }
    }

然后我在我的绘画事件中执行此操作:

I then do this in my paint event:

    private void pnlArea_Paint(object sender, PaintEventArgs e)
    {
        try
        {
            stopwatch = new Stopwatch();
            // Begin timing
            stopwatch.Start();

            if (gameStatus == GameStatus.PlaceHead)
            {
                e.Graphics.DrawImage(dictHead["HeadRight"], 100, 100, 15, 15);
            }

            //e.Graphics.Clear(Color.White);

            if (gameStatus == GameStatus.GameTest)
            {
                int x = 0;
                int y = 0;
                for (int i = 0; i < 5000; i++)
                {
                    x += 15;
                    if (x > 1000)
                    {
                        x = 0;
                        y += 15;
                    }

                    e.Graphics.DrawImage(body.Value, x, y, 15, 15);

                }
            }

            toolTimer.Text = Math.Round((stopwatch.Elapsed.TotalMilliseconds / 1000), 2).ToString() + "s";

            // Stop timing
            stopwatch.Stop();
        }
        catch (Exception)
        {

            throw;
        }
    }

这是我在上面的代码中绘制的身体部分:

This is the body part I am drawing in the code above:

这是确切的尺寸 --> 15px x 15px

This is the exact size --> 15px x 15px

但这有时需要长达 1.2 秒!!!有什么方法可以改进吗?

but this takes up to 1.2 seconds sometimes!!! is there a way I can improve this?

这是最终结果屏幕的示例:

this is a sample of the end result screen:

推荐答案

除了大家给我的信息,我得出了双缓冲面板的结论.这解决了我的问题 -->

In addition to the information everyone gave me, I came to the conclution to double buffer the panel. This fixed my problem -->

class DoubleBufferedPanel : Panel { public DoubleBufferedPanel() : base() { DoubleBuffered = true; } }

我只是使用了这个双缓冲面板.

And I just used this double buffered panel instead.

完全没有闪烁的新基准!:

New benchmark with no flickering at all! :

这篇关于图像绘制速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆