0

I using g.DrawImage for output Image like this:

g.DrawImage(Resources.dayPict, x1, myY, 20, 20);

But this way not fast. How I can draw image faster?

P.S. When I draw many images I have delays. Is there a special buffer for this goal?

  • An excellent library for drawing images and UI is http://www.vgdotnet.com/. I've used this a number of times and it is awesome. – Enigmativity Sep 10 '15 at 09:36
  • 3
    What control are you drawing it on? Have you tried setting the DoubleBuffered property on the form? I think you can double buffer other controls too, but you have to code it rather than a dedicated property. [like this for example](http://stackoverflow.com/questions/76993/how-to-double-buffer-net-controls-on-a-form) – musefan Sep 10 '15 at 09:40
  • I am using PanelControl of DevExpress. It is dublebuffered. – Evgeniy Neronov Sep 10 '15 at 09:41
  • In addition, what do you mean by "not fast"? Are you referring to a flicker, or are you really drawing so much that you get a lag with loading? Is i somthing suspendLayout might help with? Alternatively you could draw all images directly a single image in code, and then just draw that one image on your control. How many images exactly? – musefan Sep 10 '15 at 09:43
  • 2
    @musefan I don't believe _double buffering_ would help here, if anything it would slow performance not improve it. Double buffering is used to reduce _flicker_. –  Sep 10 '15 at 09:52
  • Nearly 50 images. flicker is not happend. When mouse move with pressed button my images scrolling. And when I using fillrectangle instead image scroll is very fast. When I using drawImage scroll slowly. – Evgeniy Neronov Sep 10 '15 at 09:53
  • 1
    Well drawing is a costly process so you have to optimize in other ways. For example, it may be better to move the drawing out of the paint event. How often do the images change? For example, if they don't change the you can draw them all once when the form loads, this would be a case of drawing them all to one single big image. Then you only need to draw that one image on the panel (possible in the paint event) – musefan Sep 10 '15 at 09:57
  • 1
    If you put pictureboxes on your form, and move them, that will do some builtin optimisation for you, like not drawing the images which are completely covered. Are your images transparent, or do they have opacity map? – Tamas Hegedus Sep 10 '15 at 10:02
  • Yes @musefan makes a good point about moving the draw code and using statics. You could take some tips from gaming and utilise _deferred_ rendering. Failing that you could use XNA in your WinForms app (there are articles where people have successfully fused XNA and WinForms). At least that way you benefit from hardware acceleration - something WinForms lacks. Or not sure if you want to move to WPF where it too is HW accelerated –  Sep 10 '15 at 10:03
  • OK, so you have issue with scrolling, and this will be because everything needs to redraw with each scroll change (which can be a lot). Personally I would try and do a pre-load as I have already suggested by rendering to a single image on load and then just painting that one image. If that isn't enough for whatever reason, you could then look at clipping you image when you do the paint. So that only the visible portions of your image are drawn. You would need to calculate this using scroll offsets and the likes – musefan Sep 10 '15 at 10:25
  • helped optimization: 1) is called with no size, as follows: g.DrawImage(Resources.dayPict, x1, myY); 2) Less redraw the window (only the timer, but not the mouse event) If I want to resize the Image, I will make the new Image. – Evgeniy Neronov Sep 10 '15 at 11:30

1 Answers1

1

Helped optimization:

1) Call the method with no size, like this: g.DrawImage(Resources.dayPict, x1, myY);

2) Less Invalidate the panel (only the timer, but not the mouse event)

If I want to resize the Image, I will make the new Image.