BitMap¶
继承: Resource < RefCounted < Object
布尔矩阵。
描述¶
布尔值的二维数组可用于有效地存储二进制矩阵(每个矩阵元素只占用一位)并使用自然笛卡尔坐标查询值。
方法¶
convert_to_image() const |
|
void |
|
void |
create_from_image_alpha(image: Image, threshold: float = 0.1) |
get_size() const |
|
get_true_bit_count() const |
|
void |
|
opaque_to_polygons(rect: Rect2i, epsilon: float = 2.0) const |
|
void |
|
void |
|
void |
set_bit_rect(rect: Rect2i, bit: bool) |
void |
方法说明¶
Image convert_to_image() const 🔗
返回与位图大小相同的图像,并具有Image.FORMAT_L8类型的Format。位图的true位被转换为白色像素,而false位被转换为黑色。
创建具有指定大小的位图,填充false。
void create_from_image_alpha(image: Image, threshold: float = 0.1) 🔗
创建与给定图像尺寸匹配的位图,如果该位置的图像的alpha值等于threshold或更小,则位图的每个元素都设置为false,在其他情况下设置为true。
bool get_bit(x: int, y: int) const 🔗
返回指定位置的位图值。
bool get_bitv(position: Vector2i) const 🔗
返回指定位置的位图值。
返回位图的尺寸。
int get_true_bit_count() const 🔗
返回设置为true的位图元素数。
void grow_mask(pixels: int, rect: Rect2i) 🔗
对位图应用形态膨胀或侵蚀。如果pixels为正,则对位图应用膨胀。如果pixels为负,则对位图应用侵蚀。rect定义应用形态操作的区域。位于rect之外的像素不受grow_mask()的影响。
Array[PackedVector2Array] opaque_to_polygons(rect: Rect2i, epsilon: float = 2.0) const 🔗
创建一个Array多边形,覆盖位图的矩形部分。它使用行进正方形算法,然后使用Ramer-Douglas-Peucker(RDP)减少顶点数量。每个多边形被描述为其顶点的PackedVector2Array。要获得覆盖整个位图的多边形,请传递:
Rect2(Vector2(), get_size())
epsilon被传递给RDP,用于控制多边形覆盖位图的精度:较低的epsilon对应于多边形中更多的点。
void resize(new_size: Vector2i) 🔗
将图像调整为new_size。
void set_bit(x: int, y: int, bit: bool) 🔗
将位图指定位置的元素设置为指定值。
void set_bit_rect(rect: Rect2i, bit: bool) 🔗
将位图的矩形部分设置为指定值。
void set_bitv(position: Vector2i, bit: bool) 🔗
将位图指定位置的元素设置为指定值。