This is interesting, similar to BufferedImage.createGraphics() in AWT.

Questions:

  *   so this will aways be slower than Canvas?
  *
are the results going to be exactly the same, or there will be 
platform-specific differences in anti-aliasing etc?

Thanks!
-andy


From: openjfx-dev <[email protected]> on behalf of John Hendrikx 
<[email protected]>
Date: Monday, November 10, 2025 at 06:29
To: [email protected] <[email protected]>
Subject: Feedback requested: Proof of concept PR for extending WritableImage 
with its own "graphics context" to draw higher level primitives directly :)

I've extended WritableImage with a new method `getDrawingContext`.

This method gives you a similar interface as Canvas's
`getGraphicsContext`, minus some methods that I didn't implement yet
(save/restore, font rendering, path rendering, line dashes).

The method signatures are compatible, and we could have Canvas's
GraphicsContext extend the DrawingContext interface.

Using it is trivial:

    WritableImage img = new WritableImage(400, 400);
    DrawingContext ctx = img.getDrawingContext();
    ctx.setFill(Color.RED);
    ctx.fillRect(50, 50, 100, 100);

Internally, this leverages the software renderer Pisces which is part of
JavaFX.  This means that FX can still be fully GPU accelerated, while
for drawing into a heap based WritableImage can be done with the CPU.  A
big advantage here is that this makes it possible to draw complex images
without having to snapshot them later if you need them to be images or
having to resort to drawing all primitives yourself with just a PixelWriter.

See this PR https://github.com/openjdk/jfx/pull/1969

A screenshot and demo program is included.

Feedback on the implementation is much appreciated.

--John

Reply via email to