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

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


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

if you want. it’s starts like this;

extends Node

var pictures := TileSet.new()

func _ready():
	add_child(self)