Méthode pour dessiner de façon performante
Bonjour,
ce bout de code est (très) lent. Ok il n'est pas optimisé mais tout de même...
J'aimerais connaître les techniques pour dessiner de manière efficace en .net.
Merci d'avance
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| System.Drawing.Graphics gl = Left.CreateGraphics();
System.Drawing.Graphics gr = Right.CreateGraphics();
gl.Clear( System.Drawing.Color.Black );
gr.Clear( System.Drawing.Color.Black );
System.Drawing.Pen p = new System.Drawing.Pen( System.Drawing.Color.Orange );
int h = Left.Height/2;
System.Drawing.Point[] ptsl = new System.Drawing.Point[2];
ptsl[0] = new System.Drawing.Point();
ptsl[1] = new System.Drawing.Point();
System.Drawing.Point[] ptsr = new System.Drawing.Point[2];
ptsr[0] = new System.Drawing.Point();
ptsr[1] = new System.Drawing.Point();
int b = 0;
for ( uint i = 0; i < size; ++i, b=++b%2 )
{
int x = (int)(( (double)i / (double)size ) * Left.Width);
int yl = (int)( data[0][i] * h ) + h;
int yr = (int)( data[1][i] * h ) + h;
ptsl[b].X = x;
ptsl[b].Y = yl;
ptsr[b].X = x;
ptsr[b].Y = yr;
if ( i != 0 )
{
gl.DrawLine( p, ptsl[b], ptsl[(b + 1) % 2] );
gr.DrawLine( p, ptsr[b], ptsr[(b + 1) % 2] );
}
}
gl.Dispose();
gr.Dispose(); |