Table of Contents

Class Bitmap

Namespace
Godot
Assembly
GodotSharp.dll

A two-dimensional array of boolean values, can be used to efficiently store a binary matrix (every matrix element takes only one bit) and query the values using natural cartesian coordinates.

[GodotClassName("BitMap")]
public class Bitmap : Resource, IDisposable
Inheritance
Bitmap
Implements
Inherited Members

Constructors

Bitmap()

public Bitmap()

Properties

Data

public Dictionary Data { get; set; }

Property Value

Dictionary

Methods

ConvertToImage()

Returns an image of the same size as the bitmap and with a Image.Format of type L8. true bits of the bitmap are being converted into white pixels, and false bits into black.

public Image ConvertToImage()

Returns

Image

Create(Vector2I)

Creates a bitmap with the specified size, filled with false.

public void Create(Vector2I size)

Parameters

size Vector2I

CreateFromImageAlpha(Image, float)

Creates a bitmap that matches the given image dimensions, every element of the bitmap is set to false if the alpha value of the image at that position is equal to threshold or less, and true in other case.

public void CreateFromImageAlpha(Image image, float threshold = 0.1)

Parameters

image Image
threshold float

GetBit(int, int)

Returns bitmap's value at the specified position.

public bool GetBit(int x, int y)

Parameters

x int
y int

Returns

bool

GetBitv(Vector2I)

Returns bitmap's value at the specified position.

public bool GetBitv(Vector2I position)

Parameters

position Vector2I

Returns

bool

GetSize()

Returns bitmap's dimensions.

public Vector2I GetSize()

Returns

Vector2I

GetTrueBitCount()

Returns the number of bitmap elements that are set to true.

public int GetTrueBitCount()

Returns

int

GrowMask(int, Rect2I)

Applies morphological dilation or erosion to the bitmap. If pixels is positive, dilation is applied to the bitmap. If pixels is negative, erosion is applied to the bitmap. rect defines the area where the morphological operation is applied. Pixels located outside the rect are unaffected by GrowMask(int, Rect2I).

public void GrowMask(int pixels, Rect2I rect)

Parameters

pixels int
rect Rect2I

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

OpaqueToPolygons(Rect2I, float)

Creates an Array of polygons covering a rectangular portion of the bitmap. It uses a marching squares algorithm, followed by Ramer-Douglas-Peucker (RDP) reduction of the number of vertices. Each polygon is described as a Vector2[] of its vertices.

To get polygons covering the whole bitmap, pass:

Rect2(Vector2(), get_size())

epsilon is passed to RDP to control how accurately the polygons cover the bitmap: a lower epsilon corresponds to more points in the polygons.

public Array<Vector2[]> OpaqueToPolygons(Rect2I rect, float epsilon = 2)

Parameters

rect Rect2I
epsilon float

Returns

Array<Vector2[]>

Resize(Vector2I)

Resizes the image to newSize.

public void Resize(Vector2I newSize)

Parameters

newSize Vector2I

SetBit(int, int, bool)

Sets the bitmap's element at the specified position, to the specified value.

public void SetBit(int x, int y, bool bit)

Parameters

x int
y int
bit bool

SetBitRect(Rect2I, bool)

Sets a rectangular portion of the bitmap to the specified value.

public void SetBitRect(Rect2I rect, bool bit)

Parameters

rect Rect2I
bit bool

SetBitv(Vector2I, bool)

Sets the bitmap's element at the specified position, to the specified value.

public void SetBitv(Vector2I position, bool bit)

Parameters

position Vector2I
bit bool