# What do I need the Drawing Context for?

**URL:** https://racket.discourse.group/t/what-do-i-need-the-drawing-context-for/4369
**Category:** Questions & Answers
**Tags:** question, rhombus
**Created:** [September 3, 2026, 4:10am UTC](https://racket.discourse.group/t/what-do-i-need-the-drawing-context-for/4369 "2026-09-03T04:10:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![halloleo](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@halloleo](https://racket.discourse.group/u/halloleo)
#### Post date: [September 3, 2026, 4:10am UTC](https://racket.discourse.group/t/what-do-i-need-the-drawing-context-for/4369/1 "2026-09-03T04:10:37Z")

</div>

New here - and new to Rhombus!

Via the `pict` module I generate little pictures. In the REPL they are displayed immediately.

Now I try to write the pictures to a file, so that I can run the Rhombus program from a normal shell as well (and not only from the REPL).

Say, I have my `Pict` in `def p = ...`. Claude gave me the following suggestion to write it to a file:

```rhombus
def bm = draw.Bitmap([p.width, p.height], ~backing_scale: 2)
def bm_dc = bm.make_dc()
p.draw(bm_dc)
bm_dc.write("out.png", ~kind: #'png)

```

but this gives me a "no field or method `write`" error. And indeed, the Drawing Context [doesn't have a write method](https://docs.racket-lang.org/rhombus-draw/dc.html); instead the Bitmap [has one](https://docs.racket-lang.org/rhombus-draw/bitmap.html).

So

```rhombus
def bm = draw.Bitmap([p.width, p.height], ~backing_scale: 2)
def bm_dc = bm.make_dc()
p.draw(bm_dc)
bm.write("out.png", ~kind: #'png)

```

works. But I do not understand what I then need the Drawing Context for in the first place? (I tried removing the two `bm_dc` lines, but then I do'nt see anything.)

Thanks for any help!

---

<div class="post-metadata">

### Author: ![shhyou](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@shhyou](https://racket.discourse.group/u/shhyou)
#### Post date: [September 3, 2026, 10:47am UTC](https://racket.discourse.group/t/what-do-i-need-the-drawing-context-for/4369/2 "2026-09-03T10:47:43Z")

</div>

(Static) `Pict` values can be thought as combined geometric objects. To get an image out of a `Pict`, `Bitmap` creates a blank canvas and then `def bm_dc = bm.make_dc()` prepares a drawing context, or a collection of `bm`-specific tools like pens and brushes which all draw on `bm`. Finally, `p.draw(bm_dc)` tells the `p` to draw itself (the collection of geometric objects) using the pens and brushes from `bm_dc` as a painting on the canvas.

An interesting point is that the drawing context is stateful and remembers which pen or which brush it is using. So, when a drawing context reacts to an instruction like `draw-rectangle`, it uses the color/style associated with the current pen/brush.

Here are some example programs of drawing contexts in Racket: [1&nbsp;Overview](https://docs.racket-lang.org/draw/overview.html#%28part._.Pen __.Brush__ and_.Color_.Objects%29).

---

<div class="post-metadata">

### Author: ![LiberalArtist](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/liberalartist/32/151_2.png) [@LiberalArtist](https://racket.discourse.group/u/LiberalArtist)
#### Post date: [September 3, 2026, 12:33pm UTC](https://racket.discourse.group/t/what-do-i-need-the-drawing-context-for/4369/3 "2026-09-03T12:33:00Z")

</div>

> [@halloleo](#):
>
> But I do not understand what I then need the Drawing Context for in the first place?

The Drawing Context interface is more general—bitmaps are not the only things you can draw to!

There are other drawing contexts available to generate vector graphics formats, like SVG, PDF, and EPS, and the GUI libraries add Drawing Contexts for drawing on the screen.

> **[4 Drawing Contexts](https://docs.racket-lang.org/rhombus-draw/dcs.html)**
