renderToPictureRecorder method

PictureRecorder renderToPictureRecorder(
  1. double width,
  2. double height,
  3. int bgColor
)

Renders the skeleton drawable's current pose to a PictureRecorder with the given width and height. Uses bgColor, a 32-bit ARGB color value, to paint the background. Scales and centers the skeleton to fit the within the bounds of width and height.

Implementation

PictureRecorder renderToPictureRecorder(double width, double height, int bgColor) {
  var bounds = skeleton.getBounds();
  var scale = 1 / (bounds.width > bounds.height ? bounds.width / width : bounds.height / height);

  var recorder = PictureRecorder();
  var canvas = Canvas(recorder);
  var paint = Paint()
    ..color = material.Color(bgColor)
    ..style = PaintingStyle.fill;
  canvas.drawRect(Rect.fromLTWH(0, 0, width, height), paint);
  canvas.translate(width / 2, height / 2);
  canvas.scale(scale, scale);
  canvas.translate(-(bounds.x + bounds.width / 2), -(bounds.y + bounds.height / 2));
  canvas.drawRect(const Rect.fromLTRB(-5, -5, 5, -5), paint..color = material.Colors.red);
  renderToCanvas(canvas);
  return recorder;
}