Why use an offscreen view?

In some situations, you don’t want to place the view inside an on-screen graphical user interface. Instead, you want to create a Lightspeed view that is kept off-screen, and rendered in an internal memory buffer, as a so-called offscreen view.

That may be the case if you are developing a server that builds requested images and renders them off-screen before sending them to its clients, like an OGC WMS server for instance. You can also use an off-screen view if you want to prepare an image in an internal buffer, and then display the image on-screen from the buffer at a later stage. Offscreen views can also be useful when you are setting up automated UI tests.

For all those use cases, LuciadLightspeed provides the TLspOffscreenView class.

Unlike an ILspAWTView, TLspOffscreenView does not have a host component through which it can be displayed on the screen. Other than that, it behaves exactly the same as any other ILspView implementation. TLspOffscreenView does provide the method getImage() as an alternative. It returns a screenshot of the view’s current state as a BufferedImage.

Multi-threading to support offscreen views

To paint offscreen views, you do not have to switch to the EDT. You can freely choose the thread from which you call view.paint(). It can be the EDT or any other thread. Keep in mind that you must perform all model updates on the chosen view painting thread as well, unless you use the technique described in Updating a model off the EDT.