-
- All Implemented Interfaces:
-
app.rive.core.CheckableAutoCloseable,java.lang.AutoCloseable
public final class RenderBuffer implements CheckableAutoCloseable
Represents the pixels produced by rendering a frame off-screen.
Pixels are stored in RGBA byte order, top-left origin.
⚠️ This class must be closed when you no longer need it to free its resources. The buffer creates and manages its own image surface, which is closed when the buffer is closed.
The buffer is initially empty; use snapshot to fill it with rendered content, then access the image as a bitmap through toBitmap or copyInto.
-
-
Constructor Summary
Constructors Constructor Description RenderBuffer(Integer width, Integer height, CommandQueue riveWorker)
-
Method Summary
Modifier and Type Method Description BooleangetClosed()Whether this resource has been closed. final RiveSurfacegetSurface()The underlying image surface for rendering. final IntegergetWidth()final IntegergetHeight()Unitclose()Closes this resource, releasing any underlying resources. final RenderBuffersnapshot(Artboard artboard, StateMachine stateMachine, Fit fit, Integer clearColor)Fills the buffer with rendered content from the given artboard and state machine. final BitmapcopyInto(Bitmap bitmap)Fill an existing bitmap with the contents of the buffer. final BitmaptoBitmap()Converts the buffer into an Bitmap.Config.ARGB_8888 bitmap. -
-
Constructor Detail
-
RenderBuffer
RenderBuffer(Integer width, Integer height, CommandQueue riveWorker)
- Parameters:
width- The width of the buffer in pixels.height- The height of the buffer in pixels.riveWorker- The Rive worker used to create the underlying image surface.
-
-
Method Detail
-
getSurface
final RiveSurface getSurface()
The underlying image surface for rendering. Useful to pass to Artboard.resizeArtboard when using Fit.Layout. See note in snapshot.
-
snapshot
final RenderBuffer snapshot(Artboard artboard, StateMachine stateMachine, Fit fit, Integer clearColor)
Fills the buffer with rendered content from the given artboard and state machine.
The user is responsible for advancing the state machine to the desired time before calling this method.
⚠️ If you use Fit.Layout as your fit mode, first call Artboard.resizeArtboard with your given Fit.Layout.scaleFactor to layout the artboard within your given width and height. If you need to restore the dimensions afterwards, you can call Artboard.resetArtboardSize. Also note that after calling either of these methods, you will need to advance the state machine, even if only by 0.
- Parameters:
artboard- The artboard to snapshot.stateMachine- The state machine to snapshot.fit- The fit mode to use when rendering.clearColor- The background color to use.
-
copyInto
final Bitmap copyInto(Bitmap bitmap)
Fill an existing bitmap with the contents of the buffer. The supplied bitmap must match the existing width, height, and ARGB_8888 format.
- Parameters:
bitmap- The bitmap to fill.
-
toBitmap
final Bitmap toBitmap()
Converts the buffer into an Bitmap.Config.ARGB_8888 bitmap.
If you already have a bitmap to reuse, consider using copyInto instead to avoid allocations.
-
-
-
-