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 🔗
Returns an image of the same size as the bitmap and with an Format of type Image.FORMAT_L8. true bits of the bitmap are being converted into white pixels, and false bits into black.
建立一個指定尺寸的點陣圖,用 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) 🔗
將點陣圖中指定位置的元素設定為指定值。