Wednesday, November 05, 2003

New Graphics classes for Whidbey.

The new GDI+ classes in the Whidbey alpha include classes called BufferedGraphics ans BufferedGraphicsContext.

A BufferedGraphicsContext enables you to allocate a rectangular graphics buffer, encapsulated by the BufferedGraphics class, which you can draw on using standard Graphics methods and then render at any time with a Render() method.

The following snippet shows how a buffer is allocated and drawn into. It can then be rendered at any time. In this instance I rendered it before and after painting on the graphics in the normal way.

The buffered graphics are always maintained in the allocated area.

private void Form1_Paint(object sender, PaintEventArgs e)
{
BufferedGraphicsContext c=new BufferedGraphicsContext();
BufferedGraphics bg = c.Allocate(e.Graphics,new Rectangle(10,10,200,200));

bg.Graphics.FillEllipse(Brushes.Red,0,0,300,300);

bg.Render(e.Graphics);

e.Graphics.FillEllipse(Brushes.Pink, 30, 30, 400, 20);

bg.Render(e.Graphics);
}

No comments: