J
James Chapman
Hi,
I am trying to draw a graph using System.Drawing about 5 times a
second. The graph is 700x250 pixels in size. This is proving to be
very slow.
My code currently does this in Form1_Paint:
Bitmap localBitmap = new
Bitmap(ClientRectangle.Width,ClientRectangle.Height);
Graphics bitmapGraphics = Graphics.FromImage(localBitmap);
bitmapGraphics.Clear(BackColor);
.... draws graph
g.DrawImage(localBitmap,0,0);
I have this in my Form constructor:
this.SetStyle(ControlStyles.ResizeRedraw | ControlStyles.Opaque,
true);
Is this the correct approach?
I have read that the best performance to be had from GDI+ involves
allowing it to drop through to GDI and that I should store my
offscreen buffer as a DIBSection. I have also read that it is
important to ensure that no conversion takes place when copying to the
screen due to different image formats.
Is this what I should do? How do I get a DIBSection from HBITMAP
handle into a managed Bitmap object? Or do I need to wrap unmanaged
calls to GDI+ as well as GDI.
Thanks,
James Chapman
I am trying to draw a graph using System.Drawing about 5 times a
second. The graph is 700x250 pixels in size. This is proving to be
very slow.
My code currently does this in Form1_Paint:
Bitmap localBitmap = new
Bitmap(ClientRectangle.Width,ClientRectangle.Height);
Graphics bitmapGraphics = Graphics.FromImage(localBitmap);
bitmapGraphics.Clear(BackColor);
.... draws graph
g.DrawImage(localBitmap,0,0);
I have this in my Form constructor:
this.SetStyle(ControlStyles.ResizeRedraw | ControlStyles.Opaque,
true);
Is this the correct approach?
I have read that the best performance to be had from GDI+ involves
allowing it to drop through to GDI and that I should store my
offscreen buffer as a DIBSection. I have also read that it is
important to ensure that no conversion takes place when copying to the
screen due to different image formats.
Is this what I should do? How do I get a DIBSection from HBITMAP
handle into a managed Bitmap object? Or do I need to wrap unmanaged
calls to GDI+ as well as GDI.
Thanks,
James Chapman