setPixels method

  1. @override
void setPixels(
  1. PCanvasPixels pixels, {
  2. int x = 0,
  3. int y = 0,
  4. int? width,
  5. int? height,
})
override

Sets the canvas pixels.

Implementation

@override
void setPixels(PCanvasPixels pixels,
    {int x = 0, int y = 0, int? width, int? height}) {
  pixels = pixels.toPCanvasPixelsABGR();

  var pixelsData = pixels.pixels;
  var pixelsDataBuffer = pixelsData.buffer;

  var bytes = pixelsDataBuffer.asUint8ClampedList(
      pixelsData.offsetInBytes, pixelsData.lengthInBytes);

  var imageData = ImageData(bytes, pixels.width, pixels.height);

  _ctx.putImageData(imageData, x, y, 0, 0, pixels.width, pixels.height);
}