Execution order of System.Drawing.Graphics based List<Action>

43 Views Asked by At

It's my first time posting here so apologies in advance if I get the code formatting wrong. I'm coding a simple GDI+ renderer class in C#. Here's a simplified version of my code:

public interface IRenderer
{
    void Begin();
    void ClearFrame(byte R, byte G, byte B);
    byte[] End();

}

public class RendererGDI : IRenderer
{
    List<Action> renderFunctions;
    Bitmap b = new Bitmap(256,256);
    Graphics g = Graphics.FromImage(b);

    public RendererGDI()
    {
        renderFunctions = new List<Action>();
    }

    void Begin()
    {
        renderFunctions.Clear();
    }

    void ClearFrame(byte R, byte G, byte B)
    {           
        renderFunctions.Add(() => g.Clear(Color.FromArgb(255, R,G,B)));
    }

    byte[] End()
    {
        foreach (Action func in renderFunctions)
            func();
    }
}

The End() function isn't fully implemented yet but I'm wondering if this is the correct way to store System.Drawing.Graphics operations and only have them execute inside the End() function?

Thanks very much for your time and help.

Craig.

0

There are 0 best solutions below