euclideanDistanceFlooding method
Image Euclidean distance flooding.
@offset
The starting point for image flooding.
@fillColor
The fill color of the image flood, in RGB format.
@tolerance
Color tolerance for image flooding, defaults to 1.
@isDispose
Whether to release the original image after image flooding.
Implementation
Future<Image> euclideanDistanceFlooding({
required Offset offset,
required Color fillColor,
double tolerance = 1.0,
bool isDispose = false,
}) async {
final Uint32List? uint32list = await uint32List();
if (uint32list == null || uint32list.isEmpty) return this;
final int dx = offset.dx.floor();
final int dy = offset.dy.floor();
if (dx < 0 || dx == width || dy < 0 || dy == height) return this;
final int index = (width * dy + dx).clamp(0, uint32list.length - 1);
final Color collectionColor = uint32list[index].uInt32toColor;
if (!collectionColor.euclideanDistanceColorDifference(fillColor,
tolerance: tolerance)) return this;
final Completer<Image> completer = Completer();
_floodingMethod(
uint32list,
fillColor.rgbaUInt32,
width,
height,
IntOffset(dx, dy),
(color) => collectionColor.euclideanDistanceColorDifference(color,
tolerance: tolerance));
decodeImageFromPixels(
uint32list.buffer.asUint8List(), width, height, PixelFormat.rgba8888,
(result) {
completer.complete(result);
});
if (isDispose) dispose();
return completer.future;
}