IntPixels.from constructor

IntPixels.from(
  1. Buffer<int> buffer
)

Creates a copy of the given buffer with the same pixel data and dimensions.

The format and data is copied from the given buffer.

Example

final original = IntPixels(3, 3);
final clipped = original.getRegion(Rect.fromLTWH(1, 1, 2, 2));

final copy = IntPixels.from(clipped);
print(copy.width); // 2
print(copy.height); // 2

Implementation

factory IntPixels.from(Buffer<int> buffer) {
  final data = newIntBuffer(
    bytes: buffer.format.bytesPerPixel,
    length: buffer.length,
  );
  data.setAll(0, buffer.data);
  return IntPixels(
    buffer.width,
    buffer.height,
    data: data,
    format: buffer.format,
  );
}