Performance when drawing an image

Asked

Viewed 121 times

2

Currently I use the Drawimage method of the Graphics class. However, the speed of drawing in the components is very slow. How can I optimize its use ?

Libraries like Monogame or Opentk can perform better in this regard ?

Here is an example of code in the overload of the Onpaint method.

  if (m_IsThumbnail)
        for (int j = 0; j < 3; j++)
        {
            g.DrawLine(new Pen(Color.DarkGray),
                new Point(dl + 3, dt + dh + 1 + j),
                new Point(dl + dw + 3, dt + dh + 1 + j));
            g.DrawLine(new Pen(Color.DarkGray),
                new Point(dl + dw + 1 + j, dt + 3),
                new Point(dl + dw + 1 + j, dt + dh + 3));
        }

        XImage = dl;
        YImage = dt;

        g.DrawImage(m_Image, dl, dt, dw, dh); // lentidão.
  • That’s right if without the keys ({ and })? The way it is (without the keys) it only includes the loop for and perhaps the rest (including the call from your DrawImage) is being run unnecessarily at every painting upgrade... Moreover, as your call to DrawImage size, maybe your code is doing resizing every new painting. This is often costly, and can be easily solved by keeping and reusing a previously reduced/enlarged copy of the image.

  • As for if, that’s right. In my case, the tie is not very expensive. The neck focuses on the Drawimage method. The Drawimage method no . NET is always slow. It uses GDI+, I have visited other forums and other people have the same problem of slowness when using this method.

  • Ok. Well, even so, it might be worth taking a look if your call isn’t doing any costly resizing. In this SOEN response has other tips that may also be useful. And if you’ve come up with an alternative that works better, I suggest posting an answer with her to eventually help other colleagues in the future. :)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.