mapRect method
- Rect bounds
Returns a lazy buffer that clips the buffer to the given bounds.
The returned buffer will have the same dimensions as the bounds, and will only contain pixels that are within the bounds of the original buffer; the resulting buffer must not be empty.
Example
final buffer = IntPixels(3, 3, data: Uint32List.fromList([
abgr8888.red, abgr8888.green, abgr8888.blue,
abgr8888.red, abgr8888.green, abgr8888.blue,
abgr8888.red, abgr8888.green, abgr8888.blue,
]));
final clipped = buffer.mapRect(Rect.fromLTWH(1, 1, 2, 2));
print(clipped.data); // [0xFF00FF00, 0xFF0000FF]
Implementation
Buffer<T> mapRect(Rect bounds) {
final result = bounds.intersect(this.bounds);
if (result.isEmpty) {
throw ArgumentError.value(bounds, 'bounds', 'region must be non-empty');
}
return _ClippedBuffer(this, result);
}