Saving output

On this page · 4 entries

Save

  • Save(string path, int quality = 100)

Encodes the current canvas to disk. Format is chosen from the file extension — .png, .jpg/.jpeg, .bmp, or .webp.

SaveFrame

  • SaveFrame(string pattern = "screen-####.png")

Like Save(), but substitutes # with FrameCount.

BeginRaw · EndRaw · BeginRecord · EndRecord

  • BeginRaw(string path, bool plotter = false)
  • EndRaw()
  • BeginRecord(string renderer, path)
  • EndRecord()

Exports every draw call between BeginRaw()/EndRaw() to a vector file instead of the screen; the extension picks the format: .svg writes an SVG, anything else a PDF. With plotter: true the SVG comes out ready for a pen plotter (AxiDraw, Cricut…): one layer per stroke color (one pen each), fills turned into outlines, no background, and the strokes ordered so the pen travels as little as possible in the air. BeginRecord("svg", path)/EndRecord() are aliases, like Processing's.

Redirects, doesn't fork. Real Processing draws to the screen and records at the same time. DanaProcessing instead redirects every draw call to the PDF page for the duration of the block — nothing appears on screen while a recording is active. The idiomatic pattern: factor your actual drawing into its own method, and call it twice — once normally in Draw(), once more (typically on a keypress, not every frame) wrapped in BeginRaw()/EndRaw().
C#
private void DrawPoster() { /* Background/Fill/Circle/... */ }

public override void KeyPressed()
{
    if (Key == 'v')
    {
        BeginRaw("poster.pdf");
        DrawPoster();
        EndRaw();
    }
}

Runnable example

A complete sketch using this section. Test in Dana opens it in the IDE, or paste it into a new tab and press Run.

C#
// Saving output: press S for a PNG of the canvas, R to record frames.
public class Saver : Sketch
{
    bool recording;

    public override void Setup() => Size(400, 400);

    public override void Draw()
    {
        Background(20);
        NoStroke();
        for (int i = 0; i < 8; i++)
        {
FillHSB(i * 45 + FrameCount, 70, 100);
float a = FrameCount * 0.02f + i * TWO_PI / 8;
Circle(200 + Cos(a) * 120, 200 + Sin(a) * 120, 50);
        }
        if (recording)
SaveFrame("frames/frame-####.png");     // #### becomes the frame number

        Fill(255);
        Text(recording ? "recording... (R to stop)" : "S: save PNG · R: record frames", 10, 390);
    }

    public override void KeyPressed()
    {
        if (Key == 's') { Save("snapshot.png"); Println("saved snapshot.png"); }
        if (Key == 'r') recording = !recording;
    }
}