How to cut an image into pieces and add those to a list in C#

I have been working on a color by number game with image importing in C# VB, and am converting it to Godot so I can use it on my phone.
One of the changes needed for that, is changing the code that cuts the imported image into smaller parts if the input image is still too big after downscaling.

I am having a bit of trouble with this, as the Godot library has different methods and properties with Image and Bitmap than the System.Drawing library.

Most of the other code is being converted without much trouble, but I cannot find a way to get this part to work.

This is the function as far as I could get it.

private List<Image> CutImage(Image input, int amountOnX, int amountOnY)
{
	List<Image> MultipleImages = new List<Image>();

	// Divide the image into rectangles of the same size based on the requested amount on each axis
	int index = 0;
	for (int i = 0; i < amountOnY; i++)
	{
		for (int j = 0; j < amountOnX; j++)
		{
			int partWidth = input.GetWidth() / amountOnX;
			int partHeight = input.GetHeight() / amountOnY;
			MultipleImages.Add(new Bitmap(input.GetWidth() / amountOnX, input.GetHeight() / amountOnY));
			var graphics = Graphics.FromImage(MultipleImages[index]);

			// Set the sizes of the images correct
			int n1 = input.GetWidth() / amountOnX;
			int n2 = input.GetHeight() / amountOnY;
			int n3 = j * partWidth;
			int n4 = i * partHeight;
			int n5 = partWidth;
			int n6 = partHeight;

			//make the pictures
			graphics.DrawImage(input, new Rect2(0, 0, n1, n2),
									  new Rect2(n3, n4, n5, n6), GraphicsUnit.Pixel);
			graphics.Dispose();
			index++;
		}
	}
	return MultipleImages;
}

The only things I have changed about this code from the VB version is changing the way width and height are retrieved and changing Rectangle into Rect2 since those gave me errors.

I still am getting the following 3 issues:

‘Bitmap’ does not contain a constructor that takes 2 arguments ( line 13 )
The name ‘Graphics’ does not exist in the current context ( line 14 )
The name ‘GraphicsUnit’ does not exist in the current context ( line 26 )

How do I fix these?
Or is there an alternative method exclusive to Godot that allows me to cut images in an easier way?

Preferably without bitmap as those seem to be unneeded for everything after converting since Image itself contains all the methods needed in Godot

this isnt everything you are looking for but it will get you started. note that i am using the beta which uses Image.CreateEmpty

	public MyTest() {

		// does this exists?
		if(false == ResourceLoader.Exists("res://icon.svg", "Texture2D")) {
			GD.PrintErr("ResourceLoader.Exists");
		}

		// load
		Texture2D v_texture = ResourceLoader.Load<Texture2D>("res://icon.svg", "Texture2D");
		if(null == v_texture) {
			GD.PrintErr("ResourceLoader.Load");
		}
		GD.Print("texture size w=", v_texture.GetWidth(), ",h=", v_texture.GetHeight()); // display texture width and height


		// create new image using 64 x 64 section of 128 x 128 texture
		Image v_image = Image.CreateEmpty(64, 64, false, v_texture.GetImage().GetFormat());
		v_image.BlitRect(v_texture.GetImage(), new Rect2I(32, 32, 64, 64), new Vector2I(0, 0));
		GD.Print("texture size w=", v_image.GetWidth(), ",h=", v_image.GetHeight()); // display image width and height


		// create a TextureRect and display image
		TextureRect v_texture_rect_node = new TextureRect();
		AddChild(v_texture_rect_node);
		v_texture_rect_node.Texture = ImageTexture.CreateFromImage(v_image); // convert image to imagetexture
	}

documentation

I particularly don’t understand what is going on here.


If you want to use a single image.
Default size is 16x16px

please note tilemaps are depreciated as of 4.3 (I think?)

if you want. it’s starts like this;

extends Node

var pictures := TileSet.new()

func _ready():
	add_child(self)