Re: Fast drawing of graphs

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 04/03/04


Date: Fri, 02 Apr 2004 22:41:41 -0500

Actually, if you use MFC, it is equally trivial to draw on a background bitmap; you add a
few lines of code easily cribbed from any number of Web sites and it is all done.

A more serious question is how to truly optimize the drawing. One method I used was to
compute the scaled points and save the array (about 100,000 points). I then applied (as
another answer gives) PolyLine in MM_TEXT mode to this array. As I added more points, I
would set my scaling, compute the new LPtoDP and store the DPs. The result of this was
that updates (especially when scolling, which was terribly important) were real-time. But
the downside was if the user asked to "expand axis" I had to recompute all the points,
which took long enough to require a progress bar, but then again, I was using 133MHz
machines in those days. By prescaling, I eliminated the lengthy scaling computation on
every point, and that made a difference. (Resizing the windows in the Y-direction also
required a recomputaiton, but the nature of the analysis task was that the user usually
used full-screen displays with splitter windows and never resized the windows, and only
occasionally rescaled the x-axis for magnification)
                                joe
On Thu, 01 Apr 2004 13:16:08 +0200, Bolek <kraljaprvni@volny.cz> wrote:

>Hello,
>
>I programmed a class that draws an x-y graph on a CStatic window. I used
>CClientDC for the CStatic window.
>
>If the graph has severel tens points, it is sufficiently fast. However,
>the graph may contain up to several tens thousand points and then the
>routine is very slow - about half a second or more. How can I make my
>routine faster? When I used Borland C++ Builder, this culd be easily
>achieved by not drawing directly on the, but drawing to a hidden bitmap
>and then displaying the whole bitmap at once. However I don't know how
>to do it in MSVC6.
>
>Thanks.
>
>Bolek

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm



Relevant Pages

  • Re: Thankyou
    ... The default constructor appears to set the transparency of each pixel to 100%. ... This means that if I draw something to a Bitmap and then render the bitmap, only the objects that I have drawn to the bitmap are overlayed. ... Unfortunately, the Windows control classes don't; they always paint a background, so even if you draw a transparent bitmap into the control, you can't see through it to other controls underneath. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C#) How to keep drawing graphics by GDI
    ... When the Paint event handler is called, draw ... the Bitmap to the Graphics context. ... It's just like handling the Paint event, except that the drawing is done off-screen first. ... The basic idea behind Kevin's suggestion is really the only way to accomplish this, because Windows won't remember the graphics for you implicitly. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Drawing a bitmap on screen
    ... draw stuff using Graph, but how can I put a bitmap from a file on ... I have literally been searching for hours but I can't find an ...
    (comp.lang.pascal.misc)
  • Re: Draw WMF
    ... Windows CE does not support PlayMetafile. ... Perhaps you can convert the metafile to a bitmap and then draw it. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Strategies for Text Over Video
    ... IVMRMixerBitmap9 interface. ... Draw the text into a bitmap and set it with ... graph every time, since I don't know what might be on a customer's ...
    (microsoft.public.win32.programmer.directx.video)