I am working on drawing app, which needs bucket filling also. Any idea on how to perform bucket filling in Flutter?
You would have to write your own algorithm. I think you could port this one to dart.
One fundamental you need is how to get color of a pixel of an image:
Color getPixelColor(ByteData rgbaImageData, int imageWidth, int imageHeight, int x, int y) {
assert(x >= 0 && x < imageWidth);
assert(y >= 0 && y < imageHeight);
final byteOffset = x * 4 + y * imageWidth * 4;
final r = rgbaImageData.getUint8(byteOffset);
final g = rgbaImageData.getUint8(byteOffset + 1);
final b = rgbaImageData.getUint8(byteOffset + 2);
final a = rgbaImageData.getUint8(byteOffset + 3);
return Color.fromARGB(a, r, g, b);
}
You can use it like this:
Image image = ...;
final rgbaImageData = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
print(getPixelColor(rgbaImageData, image.width, image.height, x, y));
Manipulating it follows the same scheme (setUint8
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With