铲斗加油 [英] Bucket filling in flutter
本文介绍了铲斗加油的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发绘图应用程序,该应用程序也需要填充存储桶。
关于如何在Flutter中执行桶填充的任何想法吗?
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);
}
您可以像这样使用它:
Image image = ...;
final rgbaImageData = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
print(getPixelColor(rgbaImageData, image.width, image.height, x, y));
按照相同的方案进行操作( setUint8
)。
Manipulating it follows the same scheme (setUint8
).
这篇关于铲斗加油的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文